Skip to main content

BodySource

Enum BodySource 

Source
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.

Fields

§file: File
§len: u64
§mime: &'static str
§

FileRange

A byte range of a static file.

Fields

§file: File
§total_len: u64
§mime: &'static str

Implementations§

Source§

impl BodySource

Source

pub fn kind(&self) -> BodyKind

Returns the BodyKind discriminant.

Source

pub fn len(&self) -> u64

Returns the content length in bytes, if known without performing I/O.

Source

pub fn is_empty(&self) -> bool

Returns true if the body is known to be zero-length.

Source

pub fn range(&self) -> Option<FileRange>

Returns the byte range, if this is a range body.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for BodySource

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.