Struct Response

Source
pub struct Response<'a> { /* private fields */ }

Implementations§

Source§

impl<'a> Response<'a>

Source

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: {}

Source

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}

Source

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

Source

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.
Source

pub fn write_string(&mut self, v: &str) -> ResponseConfig<'_, 'a>

Write a utf-8 String to client

Source

pub fn write_binary(&mut self, v: Vec<u8>) -> ResponseConfig<'_, 'a>

Write binary data to client

Source

pub fn write_state(&mut self, code: u16)

Only respond HTTP status to the client

Source

pub fn write_file(&mut self, path: String) -> ResponseConfig<'_, 'a>

Write file data to the client

Source

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
Source

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
Source

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

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V