Struct Request
Source pub struct Request {
pub header: Header,
pub body: Body,
}
Expand description
Handle for accessing and mutating the current HTTP request.
Handle for accessing and mutating request headers.
§body: BodyHandle for reading or writing the request body.
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).
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 }
Return the HTTP protocol version (for example, HTTP/1.1).
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 }
Return the request method (for example, GET or POST).
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 }
Replace the request method with the provided bytes.
Return the request URI as raw bytes.
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 }
Replace the request URI with the provided bytes.
👎Deprecated since 0.11.2: use the header field directly instead
Return a handle for accessing and mutating request headers.
👎Deprecated since 0.11.2: use the body field directly instead
Return a handle for reading or writing the request body.
Immutably borrows from an owned value.
Read more
Mutably borrows from an owned value.
Read more
Returns the argument unchanged.
Calls U::from(self).
That is, this conversion is whatever the implementation of
From<T> for U chooses to do.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.