pub struct Request {
pub method: String,
pub request_uri: String,
pub http_version: String,
pub headers: Vec<Header>,
pub body: Vec<u8>,
}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: Vec<u8>Raw request body bytes.
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"
pub fn get_header(&self, name: String) -> Option<&Header>
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,
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.
Trait Implementations§
impl Eq for Request
impl StructuralPartialEq for Request
Auto Trait Implementations§
impl Freeze for Request
impl RefUnwindSafe for Request
impl Send for Request
impl Sync for Request
impl Unpin for Request
impl UnsafeUnpin for Request
impl UnwindSafe for Request
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.