Skip to main content

Response

Struct Response 

Source
pub struct Response {
    pub status: i32,
    pub body: String,
    pub headers: String,
}

Fields§

§status: i32§body: String§headers: String

Implementations§

Source§

impl Response

Source

pub fn set_status(&mut self, status: i32)

Set response-status

Example

res.set_status(404);
Source

pub fn get_status(&self) -> i32

Get response-status

Example

res.get_status();
Source

pub fn send_body(&mut self, body: &str)

Send response-body as text

Example

res.send_body("body content");
Source

pub fn send_file(&mut self, path: &str)

Send response-body as file

Example

res.send_file("path.html");
Source

pub fn get_body(&self) -> String

Get response-body

Example

res.get_body();
Source

pub fn set_header(&mut self, headers: &HashMap<&str, &str>)

Send response-headers in the form of a hashmap (this will overwrite an already set header for the response)

Example

let mut headers: HashMap<&str, &str> = HashMap::new();
 
headers.insert("key", "value");
 
res.set_header(&headers);
Source

pub fn append_header(&mut self, headers: &HashMap<&str, &str>)

Append response-headers in the form of a hashmap (this will append to the already set header for the response)

Example

let mut headers: HashMap<&str, &str> = HashMap::new();
 
headers.insert("key", "value");
 
res.append_header(&headers);
Source

pub fn clear_header(&mut self)

Clear set response-header

Example

res.clear_header();
Source

pub fn set_string_header(&mut self, header: String)

Set response-header in the form of a string (this will overwrite an already set header for the response)

Example

res.set_string_header("Key: Value");
Source

pub fn append_string_header(&mut self, header: String)

Append response-header in the form of a string (this will append to the already set header for the response)

Example

res.append_string_header("Key: Value");
Source

pub fn get_header(&self) -> String

Get response-header

Example

res.get_header();
Source

pub fn redirect(&mut self, path: &str)

Redirects to given path

Example

res.redirect("/path");

Auto Trait Implementations§

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