pub struct Response<'a> { /* private fields */ }
Implementations§
Source§impl<'a> Response<'a>
impl<'a> Response<'a>
Sourcepub fn remove_header(&mut self, key: String)
pub fn remove_header(&mut self, key: String)
Remove a pair you have writed to a reponse header
- The key is not case senstive
§For example
add_header(String::from("a"),String::from("b"))
Header: {a:b}
remove_header(String::from("a"))
Header: {}
Sourcepub fn add_header(&mut self, key: String, value: String)
pub fn add_header(&mut self, key: String, value: String)
Add a pair to the header of the response
add_header(String::from("a"),String::from("b"))
Header:{a:b}
Sourcepub fn header_exist(&self, s: &str) -> bool
pub fn header_exist(&self, s: &str) -> bool
Check whether a pair exists in the header of a reponse
§For example
assume the header is {a:b}
header_exist("a")
returns true
The key is not case senstive
Sourcepub fn get_header(&self, k: &str) -> Option<&Vec<String>>
pub fn get_header(&self, k: &str) -> Option<&Vec<String>>
Get response header
- Return a Vector since a single key can correspond to multiple values in the response header.
Sourcepub fn write_string(&mut self, v: &str) -> ResponseConfig<'_, 'a>
pub fn write_string(&mut self, v: &str) -> ResponseConfig<'_, 'a>
Write a utf-8 String to client
Sourcepub fn write_binary(&mut self, v: Vec<u8>) -> ResponseConfig<'_, 'a>
pub fn write_binary(&mut self, v: Vec<u8>) -> ResponseConfig<'_, 'a>
Write binary data to client
Sourcepub fn write_state(&mut self, code: u16)
pub fn write_state(&mut self, code: u16)
Only respond HTTP status to the client
Sourcepub fn write_file(&mut self, path: String) -> ResponseConfig<'_, 'a>
pub fn write_file(&mut self, path: String) -> ResponseConfig<'_, 'a>
Write file data to the client
Sourcepub fn render_view(
&mut self,
factory: impl Fn(&Request<'_>) -> Result<String>,
context: &Request<'_>,
) -> ResponseConfig<'_, 'a>
pub fn render_view( &mut self, factory: impl Fn(&Request<'_>) -> Result<String>, context: &Request<'_>, ) -> ResponseConfig<'_, 'a>
Render a view to the client
- factory implements Fn() -> tera::Result
- The factory permits you customize the behavior of the tera engine
Sourcepub fn render_view_once(
&mut self,
path: &str,
context: &Context,
) -> ResponseConfig<'_, 'a>
pub fn render_view_once( &mut self, path: &str, context: &Context, ) -> ResponseConfig<'_, 'a>
Only use the default configured tera to render a view to the client
- path: path of view file
- context: used in the view
pub fn get_conn(&self) -> Rc<RefCell<&'a mut TcpStream>>
Auto Trait Implementations§
impl<'a> Freeze for Response<'a>
impl<'a> !RefUnwindSafe for Response<'a>
impl<'a> !Send for Response<'a>
impl<'a> !Sync for Response<'a>
impl<'a> Unpin for Response<'a>
impl<'a> !UnwindSafe for Response<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more