pub struct HttpRequest {
pub method: HttpMethod,
pub path: String,
pub version: HttpVersion,
pub headers: HashMap<String, String>,
}Expand description
Represents an HTTP request received by a client
Fields§
§method: HttpMethodHTTP Method
path: StringPath/Resource requested
version: HttpVersionHTTP Version
headers: HashMap<String, String>Headers in lowercase
Implementations§
Source§impl HttpRequest
impl HttpRequest
Sourcepub fn parse_line(
line: &str,
) -> Result<(HttpMethod, String, HttpVersion), RequestError>
pub fn parse_line( line: &str, ) -> Result<(HttpMethod, String, HttpVersion), RequestError>
Parses a raw request line (first line of an HTTP request) into an HttpRequest.
Example of a valid request line:
use coa_website::request::HttpRequest;
use coa_website::http::{HttpMethod, HttpVersion};
let line = "GET /index.html HTTP/1.1";
let (method, path, version) = HttpRequest::parse_line(line).unwrap();
assert_eq!(method, HttpMethod::GET);
assert_eq!(path, "/index.html");
assert_eq!(version, HttpVersion::Http1_1);§Errors
Returns an error if the request line is malformed or unsupported.
Sourcepub async fn from_async_reader(
reader: &mut (impl AsyncBufRead + Unpin),
) -> Result<Self, RequestError>
pub async fn from_async_reader( reader: &mut (impl AsyncBufRead + Unpin), ) -> Result<Self, RequestError>
Asynchronously reads and parses a full HTTP request from the provided reader
Trait Implementations§
Auto Trait Implementations§
impl Freeze for HttpRequest
impl RefUnwindSafe for HttpRequest
impl Send for HttpRequest
impl Sync for HttpRequest
impl Unpin for HttpRequest
impl UnwindSafe for HttpRequest
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