pub enum Body {
Empty,
Static(&'static [u8]),
Bytes(Vec<u8>),
Stream(Box<dyn Iterator<Item = Vec<u8>> + Send>),
File {
fd: OwnedFd,
offset: u64,
len: u64,
},
Raw(&'static [u8]),
}Expand description
The body of an HTTP response.
Supports multiple storage strategies: zero-copy static slices, heap-allocated
bytes, streaming iterators, and kernel-level sendfile for files.
Variants§
Empty
No body content.
Static(&'static [u8])
A compile-time static byte slice — zero allocation, zero copy.
Bytes(Vec<u8>)
Heap-allocated byte vector.
Stream(Box<dyn Iterator<Item = Vec<u8>> + Send>)
Chunked streaming body — each call to next() yields a chunk.
File
Zero-copy file body — served via sendfile() entirely in kernel space.
The fd is owned and will be closed when the response is consumed or dropped.
Raw(&'static [u8])
Fully pre-baked raw HTTP response (status line + headers + body) as a static byte slice. The worker writes this verbatim, bypassing ALL header serialization logic. Maximum throughput — zero overhead.
Use Response::raw to construct. You are responsible for producing a
valid HTTP/1.1 response including “\r\n\r\n” and the body.