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§
fn set_status(&mut self, code: u16)
fn set_header(&mut self, key: &str, value: &str)
Provided Methods§
Sourcefn remove_header(&mut self, _key: &str)
fn remove_header(&mut self, _key: &str)
Remove a response header by name. Default is a no-op.
Sourcefn 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 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.
Sourcefn body_bytes(&self) -> Vec<u8> ⓘ
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.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".