pub struct Request {
pub ip: SocketAddr,
pub url: String,
pub method: Method,
pub body: Vec<u8>,
pub headers: HashMap<String, String>,
}
Expand description
A server request. Parses the raw request string into a more usable format.
Fields§
§ip: SocketAddr
The ip from the socket connection.
url: String
Raw URL string.
Use Request::parse_url()
to get a parsed version of the URL
method: Method
Method used in the request. Might be Method::Unknown if parsing fails.
body: Vec<u8>
Body of the request, in bytes.
Use Request::text
, [Request::json
], or [Request::force_json
]
to get a parsed version of the body.
headers: HashMap<String, String>
Parsed headers.
Implementations§
source§impl Request
impl Request
sourcepub fn new(bytes: &[u8], ip: SocketAddr) -> Option<Self>
pub fn new(bytes: &[u8], ip: SocketAddr) -> Option<Self>
Parses and creates a requeset from raw text and an ip address. Note that this does not parse the url (See Request::url).
sourcepub fn get_header(&self, key: &str) -> Option<&str>
pub fn get_header(&self, key: &str) -> Option<&str>
Safely gets a header.
sourcepub fn get_header_or(&self, key: &str, default: &'static str) -> &str
pub fn get_header_or(&self, key: &str, default: &'static str) -> &str
Equivalent to get_header(key).unwrap_or(default)
sourcepub fn has_header(&self, key: &str) -> bool
pub fn has_header(&self, key: &str) -> bool
Checks if a header exists.
sourcepub fn set_header<T: ToString, K: ToString>(&mut self, k: T, v: K)
pub fn set_header<T: ToString, K: ToString>(&mut self, k: T, v: K)
Sets a header using any key and value convertible to Strings
sourcepub fn text(&self) -> Cow<'_, str>
pub fn text(&self) -> Cow<'_, str>
Gets the body as a string.
See String::from_utf8_lossy
Trait Implementations§
source§impl PartialEq for Request
impl PartialEq for Request
impl Eq for Request
impl StructuralEq for Request
impl StructuralPartialEq for Request
Auto Trait Implementations§
impl RefUnwindSafe for Request
impl Send for Request
impl Sync for Request
impl Unpin 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
Mutably borrows from an owned value. Read more