Skip to main content

Request

Struct Request 

Source
pub struct Request {
    pub header: Header,
    pub body: Body,
}
Expand description

Handle for accessing and mutating the current HTTP request.

Fields§

§header: Header

Handle for accessing and mutating request headers.

§body: Body

Handle for reading or writing the request body.

Implementations§

Source§

impl Request

Source

pub fn source_addr(&self) -> Bytes

Return the client source address (ip:port) as raw bytes.

§Example
  • IPv6 b“[fe80::90f4:16ff:fee0:24b3%enp5s0]:41236“
  • IPv4 b“1.1.1.1:12345“

Supported are both IPv4 and IPv6

§Note

A host who fails to get the remote address will trap (aka panic, “unreachable” instruction).

Examples found in repository?
examples/info.rs (line 18)
17    fn handle_request(&self, request: &Request, _response: &Response) -> (bool, i32) {
18        info!("Request: {} {} {} {}", request.method(), request.version(), request.uri(), request.source_addr());
19        for (name, values) in request.header.entries_iter() {
20            let values = values.iter().map(|v| format!("{v}")).collect::<Vec<_>>().join(", ");
21            info!("Header: {} [{}]", name, values);
22        }
23        info!("Body: {}", request.body.read());
24        (true, 0)
25    }
Source

pub fn version(&self) -> Bytes

Return the HTTP protocol version (for example, HTTP/1.1).

Examples found in repository?
examples/info.rs (line 18)
17    fn handle_request(&self, request: &Request, _response: &Response) -> (bool, i32) {
18        info!("Request: {} {} {} {}", request.method(), request.version(), request.uri(), request.source_addr());
19        for (name, values) in request.header.entries_iter() {
20            let values = values.iter().map(|v| format!("{v}")).collect::<Vec<_>>().join(", ");
21            info!("Header: {} [{}]", name, values);
22        }
23        info!("Body: {}", request.body.read());
24        (true, 0)
25    }
Source

pub fn method(&self) -> Bytes

Return the request method (for example, GET or POST).

Examples found in repository?
examples/info.rs (line 18)
17    fn handle_request(&self, request: &Request, _response: &Response) -> (bool, i32) {
18        info!("Request: {} {} {} {}", request.method(), request.version(), request.uri(), request.source_addr());
19        for (name, values) in request.header.entries_iter() {
20            let values = values.iter().map(|v| format!("{v}")).collect::<Vec<_>>().join(", ");
21            info!("Header: {} [{}]", name, values);
22        }
23        info!("Body: {}", request.body.read());
24        (true, 0)
25    }
Source

pub fn set_method(&self, method: &[u8])

Replace the request method with the provided bytes.

Source

pub fn uri(&self) -> Bytes

Return the request URI as raw bytes.

Examples found in repository?
examples/info.rs (line 18)
17    fn handle_request(&self, request: &Request, _response: &Response) -> (bool, i32) {
18        info!("Request: {} {} {} {}", request.method(), request.version(), request.uri(), request.source_addr());
19        for (name, values) in request.header.entries_iter() {
20            let values = values.iter().map(|v| format!("{v}")).collect::<Vec<_>>().join(", ");
21            info!("Header: {} [{}]", name, values);
22        }
23        info!("Body: {}", request.body.read());
24        (true, 0)
25    }
Source

pub fn set_uri(&self, uri: &[u8])

Replace the request URI with the provided bytes.

Source

pub fn header(&self) -> &Header

👎Deprecated since 0.11.2:

use the header field directly instead

Return a handle for accessing and mutating request headers.

Source

pub fn body(&self) -> &Body

👎Deprecated since 0.11.2:

use the body field directly instead

Return a handle for reading or writing the request body.

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.