ResponseBody

Struct ResponseBody 

Source
pub struct ResponseBody(/* private fields */);

Implementations§

Source§

impl ResponseBody

Source

pub fn from_entity<T: Any + Send + Debug + 'static>( entity: T, serializer: impl EntitySerializer<T> + 'static, ) -> Self

Source

pub fn from_data(data: Vec<u8>) -> Self

Source

pub fn from_externally_gzipped_data(data_in_gzip_format: Vec<u8>) -> Self

Will send data that has been externally gzipped. the data is assumed to be in gzip format and this is not checked.

Source

pub fn from_data_with_gzip_in_memory(data: impl AsRef<[u8]>) -> Self

Will gzip the data in memory and then send the compressed version of the data.

Source

pub fn from_string(data: impl ToString) -> Self

Source

pub fn from_slice<T: AsRef<[u8]> + ?Sized>(data: &T) -> Self

Source

pub fn from_static_slice(data: &'static [u8]) -> Self

Creates a response body from a static slice. Unlike the other fn’s that accepts borrowed data, this fn does not copy the slice.

This is useful for usage with include_bytes!.

Source

pub fn from_file<T: Read + Seek + Send + 'static>(file: T) -> Result<Self>

Source

pub fn from_file_with_chunked_gzip<T: Read + Seek + Send + 'static>( file: T, ) -> Self

Source

pub fn from_externally_gzipped_file<T: Read + Seek + Send + 'static>( file_in_gzip_format: T, ) -> Result<Self>

Source

pub fn chunked<T: FnOnce(&dyn ResponseBodySink) -> Result<()> + Send + 'static>( streamer: T, ) -> Self

Source

pub fn streamed<T: FnOnce(&dyn ResponseBodySink) -> Result<()> + Send + 'static>( streamer: T, ) -> Self

Source

pub fn chunked_gzip<T: FnOnce(&dyn ResponseBodySink) -> Result<()> + Send + 'static>( streamer: T, ) -> Self

Creates a response body that streams data from a sink and will on the fly gzip it. Due to gzip encoding the implementation does not guarantee that each written chunk corresponds to exactly one http chunk and also does not guarantee that any such chunk is written immediately.

Source

pub fn serialize_entity(self, mime: &MimeType) -> TiiResult<ResponseBody>

This fn causes entity data to be serialized into a Vec After this further dynamic operations on the entity are no longer possible. This call also Drop’s the entity. It has no effect on other Body types.

Source

pub fn get_entity(&self) -> Option<&dyn Any>

If this body refers to a dynamic entity then return a dyn Any handle of the dynamic entity.

Source

pub fn get_entity_mut(&mut self) -> Option<&mut dyn Any>

If this body refers to a dynamic entity then return a mut dyn Any handle of the dynamic entity.

Source

pub fn get_entity_serializer(&self) -> Option<&dyn Any>

Source

pub fn get_entity_serializer_mut(&mut self) -> Option<&mut dyn Any>

Source

pub fn try_into_entity(self) -> Result<(Box<dyn Any>, Box<dyn Any>), Self>

Will decode the generic entity into a tuple of Entity, Serializer. Both as Box dyn Any. If the body is not an entity then this will yield Err(Self)

Source

pub fn write_to_raw( self, mime: &MimeType, stream: &mut impl Write, ) -> TiiResult<()>

This function writes the raw bytes of the body to a stream. It is useful if a filter wishes to retrieve the raw data and inspect it. This raw data does not have any http specific content or transfer encoding applies and contains the raw bytes just like the other side should interpret them after undoing the encodings.

Source

pub fn write_to_http<T: ConnectionStreamWrite + ?Sized>( self, request_id: u128, stream: &T, ) -> TiiResult<()>

This fn writes the body to a stream in http format. Its expected that the stream just finished writing the last header. This fn will handle things like transfer/content encoding (not the header part) for the body transparently. So a chunked stream will be in the http chunked format for example.

Source

pub fn is_entity(&self) -> bool

Source

pub fn is_chunked(&self) -> bool

Source

pub fn get_content_encoding(&self) -> Option<&'static str>

Source

pub fn content_length(&self) -> Option<u64>

Trait Implementations§

Source§

impl Debug for ResponseBody

Source§

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

Formats the value using the given formatter. Read more
Source§

impl From<&[u8]> for ResponseBody

Source§

fn from(value: &[u8]) -> Self

Converts to this type from the input type.
Source§

impl From<&str> for ResponseBody

Source§

fn from(value: &str) -> Self

Converts to this type from the input type.
Source§

impl From<String> for ResponseBody

Source§

fn from(value: String) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<u8>> for ResponseBody

Source§

fn from(value: Vec<u8>) -> Self

Converts to this type from the input type.
Source§

impl TryFrom<&Path> for ResponseBody

Source§

type Error = Error

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

fn try_from(value: &Path) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&PathBuf> for ResponseBody

Source§

type Error = Error

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

fn try_from(value: &PathBuf) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<File> for ResponseBody

Source§

type Error = Error

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

fn try_from(value: File) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<PathBuf> for ResponseBody

Source§

type Error = Error

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

fn try_from(value: PathBuf) -> Result<Self, Self::Error>

Performs the conversion.

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<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> Same for T

Source§

type Output = T

Should always be Self
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.