Struct Request

Source
pub struct Request {
    pub args: HashMap<String, String>,
    pub data: HashMap<String, String>,
    pub params: HashMap<String, String>,
    /* private fields */
}
Expand description

HTTP Request

Fields§

§args: HashMap<String, String>§data: HashMap<String, String>§params: HashMap<String, String>

Implementations§

Source§

impl Request

Source

pub fn new( method: &str, uri: &str, headers: HashMap<String, String>, body: &[u8], ) -> Self

Create a new Request

§Example
use std::collections::HashMap;
use haro::Request;

let headers = HashMap::new();
let body = &Vec::new();
let mut req = Request::new("get", "/", headers, body);
Source

pub fn from(conn: &mut Conn) -> Self

Create a new Request from a TCP connectio

Source

pub fn method(&self) -> &str

HTTP method for current Request

Examples found in repository?
examples/cookie/main.rs (line 23)
21fn hello(req: Request) -> Response {
22    let data = json!({
23        "method":req.method(),
24        "args":req.args,
25        "params":req.params,
26        "data":req.data,
27    });
28    Response::json(data)
29}
More examples
Hide additional examples
examples/hello_world/main.rs (line 18)
16fn hello(req: Request) -> Response {
17    let data = json!({
18        "method":req.method(),
19        "args":req.args,
20        "params":req.params,
21        "data":req.data,
22    });
23    Response::json(data)
24}
examples/middleware/main.rs (line 21)
19fn hello(req: Request) -> Response {
20    let data = json!({
21        "method":req.method(),
22        "args":req.args,
23        "params":req.params,
24        "data":req.data,
25    });
26    Response::json(data)
27}
examples/readme/main.rs (line 17)
15fn input(req: Request) -> Response {
16    let data = json!({
17        "method":req.method(),
18        "args":req.args,
19        "params":req.params,
20        "data":req.data,
21    });
22    Response::json(data)
23}
examples/test/main.rs (line 23)
21fn hello(req: Request) -> Response {
22    let data = json!({
23        "method":req.method(),
24        "args":req.args,
25        "params":req.params,
26        "data":req.data,
27    });
28    Response::json(data)
29}
Source

pub fn path(&self) -> &str

HTTP path for current Request

Source

pub fn full_path(&self) -> &str

HTTP full path with query args

Source

pub fn headers(&self) -> &HeaderMap<HeaderValue>

HTTP headers for current Request

Source

pub fn cookies(&self) -> HashMap<String, String>

HTTP cookies for current Request

Examples found in repository?
examples/cookie/main.rs (line 33)
31fn session_middleware(next: DynHandler) -> DynHandler {
32    Arc::new(move |req: Request| -> Response {
33        let cookies = req.cookies();
34        println!("get cookies: {cookies:?}");
35
36        let mut res = next(req);
37
38        let cookie1 = Cookie::build("foo", "bar").finish();
39        let cookie2 = Cookie::build("bar", "baz")
40            .domain("example.coom")
41            .path("/")
42            .secure(true)
43            .http_only(true)
44            .finish();
45        res = res.header(SET_COOKIE, &cookie1.to_string());
46        res.header(SET_COOKIE, &cookie2.to_string())
47    })
48}

Trait Implementations§

Source§

impl Debug for Request

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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.