RequestChunkSource
struct RequestChunkSourceA ChunkSource that yields successive slices of a request body as bounded-size chunks.
Owns no state beyond the underlying List[UInt8] (held by
the request that constructed this source — do not outlive
the source request) and a few bookkeeping fields:
buf— owned copy of the request body bytes; cheap to construct (oneList[UInt8]clone) and lets the source outlive the originatingRequestif the handler needs to.cursor— byte offset of the next chunk withinbuf.chunk_size— max bytes per yielded chunk.cancel_check_chunks— how often the source should poll theCanceltoken; default is every chunk. Bumping this can shave the per-chunk cost on tight loops where cancellation latency tolerates a few-chunks delay.
The trait contract says the chunk returned must remain
valid until the next next call. This impl returns a
freshly-allocated List[UInt8] per chunk (the slice is
copied out of buf), so callers can stash the chunk
indefinitely if they want — no aliasing issues.
Implements ChunkSource, Movable
- Fields
buf: List[UInt8]cursor: Intchunk_size: Intcancel_check_chunks: Int
of
def of(req: Request) -> Self Build a source pulling from req.body with default chunk size (64 KiB).
of_with_chunk_size
def of_with_chunk_size(req: Request, chunk_size: Int) -> Self Build a source pulling from req.body with a caller-specified chunk size.
Raises :class:flare.errors.ValidationError (field= "chunk_size") on chunk_size <= 0 so the source
can't enter an infinite loop emitting empty chunks.
next
def next(mut self, cancel: Cancel) -> Optional[List[UInt8]] Yield the next chunk, or None at end-of-body.
Polls cancel.cancelled() every
cancel_check_chunks calls (default: every call). On
cancel, returns None so the handler's iteration
terminates cleanly without raising.
remaining
def remaining(self) -> Int Number of bytes that have not yet been emitted as chunks. Returns 0 when fully drained.
total
def total(self) -> Int Total number of bytes in the body (constant once constructed).