pub enum BodySource {
Empty,
Bytes(Vec<u8>),
FileFull {
file: File,
len: u64,
mime: &'static str,
},
FileRange {
file: File,
range: FileRange,
total_len: u64,
mime: &'static str,
},
}Expand description
A resolved response body that owns its data without reopening paths.
For file-backed variants, the File was opened during path resolution
(e.g. via openat(O_NOFOLLOW) on Unix) and is carried forward here.
The service layer converts it to a Hyper streaming body at response time.
Variants§
Empty
No body content (e.g. HEAD response, 304, 416).
Bytes(Vec<u8>)
An in-memory byte buffer.
FileFull
A full static file. The file was opened during resolution.
FileRange
A byte range of a static file.
Implementations§
Source§impl BodySource
impl BodySource
Sourcepub fn read_all(&mut self) -> Result<Vec<u8>>
pub fn read_all(&mut self) -> Result<Vec<u8>>
Read the entire body into memory.
This is suitable for small files and test verification. For production streaming, the service layer should convert the body source to a Hyper streaming body instead of reading into memory.
§Errors
Returns an I/O error if the file cannot be read or the range cannot be seeked to.
Sourcepub fn read_all_bounded(&mut self, max_bytes: usize) -> Result<Vec<u8>>
pub fn read_all_bounded(&mut self, max_bytes: usize) -> Result<Vec<u8>>
Read the entire body into memory, capped at max_bytes.
Returns at most max_bytes bytes. If the body is larger, the excess
is silently truncated. This prevents unbounded allocation when reading
file-backed bodies whose size may be large.
§Errors
Returns an I/O error if the file cannot be read or the range cannot be seeked to.
Sourcepub fn read_range(&mut self, start: u64, end_inclusive: u64) -> Result<Vec<u8>>
pub fn read_range(&mut self, start: u64, end_inclusive: u64) -> Result<Vec<u8>>
Read a specific byte range from the body.
For file-full bodies, start and end_inclusive are absolute offsets
into the file. For file-range bodies, they are offsets within the range.
§Errors
Returns an I/O error if the seek or read fails.