pub struct ResponseBody(/* private fields */);Implementations§
Source§impl ResponseBody
impl ResponseBody
pub fn from_entity<T: Any + Send + Debug + 'static>( entity: T, serializer: impl EntitySerializer<T> + 'static, ) -> Self
pub fn from_data(data: Vec<u8>) -> Self
Sourcepub fn from_externally_gzipped_data(data_in_gzip_format: Vec<u8>) -> Self
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.
Sourcepub fn from_data_with_gzip_in_memory(data: impl AsRef<[u8]>) -> Self
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.
pub fn from_string(data: impl ToString) -> Self
pub fn from_slice<T: AsRef<[u8]> + ?Sized>(data: &T) -> Self
Sourcepub fn from_static_slice(data: &'static [u8]) -> Self
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!.
pub fn from_file<T: Read + Seek + Send + 'static>(file: T) -> Result<Self>
pub fn from_file_with_chunked_gzip<T: Read + Seek + Send + 'static>( file: T, ) -> Self
pub fn from_externally_gzipped_file<T: Read + Seek + Send + 'static>( file_in_gzip_format: T, ) -> Result<Self>
pub fn chunked<T: FnOnce(&dyn ResponseBodySink) -> Result<()> + Send + 'static>( streamer: T, ) -> Self
pub fn streamed<T: FnOnce(&dyn ResponseBodySink) -> Result<()> + Send + 'static>( streamer: T, ) -> Self
Sourcepub fn chunked_gzip<T: FnOnce(&dyn ResponseBodySink) -> Result<()> + Send + 'static>(
streamer: T,
) -> Self
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.
Sourcepub fn serialize_entity(self, mime: &MimeType) -> TiiResult<ResponseBody>
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.
Sourcepub fn get_entity(&self) -> Option<&dyn Any>
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.
Sourcepub fn get_entity_mut(&mut self) -> Option<&mut dyn Any>
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.
pub fn get_entity_serializer(&self) -> Option<&dyn Any>
pub fn get_entity_serializer_mut(&mut self) -> Option<&mut dyn Any>
Sourcepub fn try_into_entity(self) -> Result<(Box<dyn Any>, Box<dyn Any>), Self>
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)
Sourcepub fn write_to_raw(
self,
mime: &MimeType,
stream: &mut impl Write,
) -> TiiResult<()>
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.
Sourcepub fn write_to_http<T: ConnectionStreamWrite + ?Sized>(
self,
request_id: u128,
stream: &T,
) -> TiiResult<()>
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.