InlineBody
struct InlineBody
Single-shot body — the prior List[UInt8] shape packaged as a Body impl.
On the first call to next_chunk returns the entire byte
buffer; on subsequent calls returns None. content_length()
is the buffer's length.
Use this when the handler can produce the entire body before
returning (the typical request / response flow). For streaming
cases reach for ChunkedBody.
Implements Body, Movable
__init__
def __init__(out self, var bytes: List[UInt8])
content_length
def content_length(self) -> Optional[Int]
next_chunk
def next_chunk(mut self, cancel: Cancel) -> Optional[List[UInt8]]
ChunkedBody
struct ChunkedBody[Source: ChunkSource]
Adapts a ChunkSource to the Body trait.
content_length() is always None (chunked sources have
no fixed length); the reactor will use Transfer-Encoding: chunked framing when this body is rendered. The Source's
next(cancel) is forwarded directly.
Example:
struct Counter(ChunkSource):
var i: Int
var buf: String
def next(mut self, cancel: Cancel) raises -> Optional[List[UInt8]]:
if cancel.cancelled() or self.i >= 100:
return Optional[List[UInt8]]()
self.buf = "data: " + String(self.i) + "\n\n"
self.i += 1
var out = List[UInt8]()
for b in self.buf.as_bytes():
out.append(b)
return Optional[List[UInt8]](out^)
Implements Body, Movable
- Fields
source: Source
__init__
def __init__(out self, var source: Source)
content_length
def content_length(self) -> Optional[Int]
next_chunk
def next_chunk(mut self, cancel: Cancel) -> Optional[List[UInt8]]