pub struct Request {
pub method: String,
pub request_uri: String,
pub http_version: String,
pub headers: Vec<Header>,
pub body: Body,
}Expand description
A parsed HTTP request.
Fields§
§method: StringHTTP method: "GET", "POST", etc. Compare with METHOD constants.
request_uri: StringRequest URI including path and query string, e.g. "/search?q=rust".
http_version: StringHTTP version string, e.g. "HTTP/1.1". Compare with crate::http::VERSION constants.
headers: Vec<Header>Request headers.
body: BodyThe request body: its bytes (&request.body[..], request.body.len())
— or, for an application that opted in with
Application::streams_body,
a stream to read as it arrives. See Body.
Implementations§
Source§impl Request
impl Request
pub const _ERROR_UNABLE_TO_PARSE_METHOD_AND_REQUEST_URI_AND_HTTP_VERSION: &'static str = "Unable to parse method, request uri and http version"
Sourcepub const PURGE: &'static str = "PURGE"
pub const PURGE: &'static str = "PURGE"
The cache purge method (nginx/Varnish), accepted since 18.11.0 so a
CacheLayer with a purge token can answer
it; anything else treats it like any unrouted method.
Sourcepub fn get_header(&self, name: String) -> Option<&Header>
pub fn get_header(&self, name: String) -> Option<&Header>
The first header named name (case-insensitive). Prefer
Request::header, which needs no String.
Sourcepub fn header(&self, name: &str) -> Option<&Header>
pub fn header(&self, name: &str) -> Option<&Header>
The first header named name, compared case-insensitively without
allocating (this used to lowercase every header name on every lookup).
pub fn get_domain(&self) -> Result<Option<String>, String>
pub fn get_port(&self) -> Result<Option<i128>, String>
pub fn get_query(&self) -> Result<Option<HashMap<String, String>>, String>
pub fn get_uri_query(&self) -> Result<Option<HashMap<String, String>>, String>
pub fn get_path(&self) -> Result<String, String>
pub fn get_uri_path(&self) -> Result<String, String>
Sourcepub fn is_supported_method(method: &str) -> bool
pub fn is_supported_method(method: &str) -> bool
true if method (any case) is one of Request::method_list or
PURGE, without building that list — it’s checked
on every request.
pub fn method_list() -> Vec<String>
pub fn generate(&self) -> Vec<u8> ⓘ
pub fn generate_request(request: Request) -> String
pub fn _generate_request(request: Request) -> String
pub fn parse(request_vec_u8: &[u8]) -> Result<Request, String>
pub fn parse_request(request_vec_u8: &[u8]) -> Result<Request, String>
pub fn parse_method_and_request_uri_and_http_version_string( http_version_status_code_reason_phrase: &str, ) -> Result<(String, String, String), String>
Sourcepub fn normalize_request_target(target: &str) -> Option<String>
pub fn normalize_request_target(target: &str) -> Option<String>
RFC 9112 §3.2 request targets: origin-form (/path?query) is kept,
absolute-form (http://host/path?query) is reduced to its
origin-form path, asterisk-form (*) is kept. Anything else —
authority-form (host:443, CONNECT is not served) or junk like :x —
is None, so the request is rejected before reaching a controller.
Sourcepub fn parse_http_request_header_string(header_string: &str) -> Header
pub fn parse_http_request_header_string(header_string: &str) -> Header
Name: value → Header. The name ends at the first :; the value
is everything after it, without surrounding spaces/tabs (RFC 9112
§5.1). Splitting on every “: “ used to cut a value that itself
contained “: “ short, and Name:value (no space) had an empty value.
Sourcepub fn cursor_read(
cursor: &mut Cursor<&[u8]>,
iteration_number: usize,
request: &mut Request,
content_length: usize,
) -> Result<bool, String>
pub fn cursor_read( cursor: &mut Cursor<&[u8]>, iteration_number: usize, request: &mut Request, content_length: usize, ) -> Result<bool, String>
Parse the request line, headers, and body from cursor into request.
Iterative: this used to recurse once per header line, so a single request with a few thousand short header lines overflowed the worker thread’s stack and aborted the whole process. Errors anywhere in the head (bad UTF-8, an invalid Content-Length) are returned instead of being logged and dropped.