Skip to main content

IHttpResponse

Trait IHttpResponse 

Source
pub trait IHttpResponse: Send {
    // Required methods
    fn status(&self) -> u16;
    fn set_status(&mut self, code: u16);
    fn set_header(&mut self, key: &str, value: &str);
    fn write_bytes<'life0, 'async_trait>(
        &'life0 mut self,
        data: Vec<u8>,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn remove_header(&mut self, _key: &str) { ... }
    fn has_body(&self) -> bool { ... }
    fn write_text<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        text: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn body_bytes(&self) -> Vec<u8>  { ... }
    fn header(&self, _key: &str) -> Option<&str> { ... }
}
Expand description

HTTP response abstraction.

Analogous to ASP.NET Core’s HttpResponse.

Methods are non-generic to maintain dyn-compatibility.

Required Methods§

Source

fn status(&self) -> u16

Get the current HTTP status code.

Source

fn set_status(&mut self, code: u16)

Source

fn set_header(&mut self, key: &str, value: &str)

Source

fn write_bytes<'life0, 'async_trait>( &'life0 mut self, data: Vec<u8>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Write raw bytes as the response body.

Provided Methods§

Source

fn remove_header(&mut self, _key: &str)

Remove a response header by name. Default is a no-op.

Source

fn has_body(&self) -> bool

Whether a response body has been written.

Source

fn write_text<'life0, 'life1, 'async_trait>( &'life0 mut self, text: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Write a UTF-8 string as the response body.

Source

fn body_bytes(&self) -> Vec<u8>

Read the current response body bytes.

Returns an empty Vec if no body has been written. Used by post-processing middleware (e.g. compression) in after hooks.

Source

fn header(&self, _key: &str) -> Option<&str>

Read a response header value by name.

Returns None if the header is not set. Used by post-processing middleware (e.g. compression) to inspect content-type.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§