Struct Request

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

Implementations§

Source§

impl<'a> Request<'a>

Source

pub fn get_header(&self, key: &str) -> Option<&str>

Get the value of a header pair by specifying the key For example, Content-length: 123 get_header(“Content-length”), the key is not case senstive

Source

pub fn get_param(&self, k: &str) -> Option<&str>

Get the value of a parameter in the requested url

§For example

/path?id=1

  • get_param("id") returns 1, the key is case senstive
Source

pub fn get_params(&self) -> Option<HashMap<&str, &str>>

Get the HashMap of the parameters in the requested url

§For example

/path?id=1&flag=true

  • get_params() returns {id:1, flag:true }
Source

pub fn get_headers(&self) -> HashMap<&str, &str>

Get the complete http headers

  • {"Content-length":"1", "key":"value",...}
Source

pub fn get_version(&self) -> &str

Get the version of http request

Source

pub fn get_query(&self, k: &str) -> Option<&str>

Query the value of www-form-urlencoded or the text part of the multipart-form

  • The key is not case senstive
§For example

Assume the form has the value id=1, then get_query(“id”) returns Some(“1”)

Source

pub fn get_file(&self, k: &str) -> Option<&MultipleFormFile>

This method is used to acquire the file in the multipart-form data

§For example,
<form>
   <input type="file" name="file1" />
</form>
  • get_file("file1") return the file’s meta data
Source

pub fn get_queries(&self) -> Option<HashMap<&str, &str>>

Return a HashMap that comprises all pairs in the www-form-urlencoded or the text part of the multipart-form

  • It is safety called even though the request is GET, which returns None
Source

pub fn get_files(&self) -> Option<Vec<&MultipleFormFile>>

Returns an array comprises of all files in the multipart-form data

Source

pub fn plain_body(&self) -> Option<&str>

Returns the body of a request

  • it is used for getting the posted JSON or other plain text body
Source

pub fn has_body(&self) -> bool

Determin whether the request has a body

Source

pub fn get_conn(&self) -> Rc<RefCell<&'a mut TcpStream>>

Return the raw instance of TcpStream

  • This method should be carefully used, It is better to only get some meta information of a connection, such as a peer IP
Source

pub fn get_method(&self) -> &str

Return the requested http method

Source

pub fn get_url(&self) -> &str

Return the complete requested url

Source

pub fn url_to_path(&self) -> &str

Return the part of url exclude the parameters(if any)

Source

pub fn get_context(&self) -> &RefCell<BTreeMap<String, Value>>

It is used to store user data

  • share data between middlwares and routers(if any)

Auto Trait Implementations§

§

impl<'a> !Freeze for Request<'a>

§

impl<'a> !RefUnwindSafe for Request<'a>

§

impl<'a> !Send for Request<'a>

§

impl<'a> !Sync for Request<'a>

§

impl<'a> Unpin for Request<'a>

§

impl<'a> !UnwindSafe for Request<'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