pub struct Request {
pub request_line: RequestLine,
pub headers: Headers,
pub body: Option<Body>,
pub files: Vec<File>,
}
Expand description
Wrapper over an HTTP Request.
Fields§
§request_line: RequestLine
The request line of the request.
headers: Headers
The headers of the request.
body: Option<Body>
The body of the request.
files: Vec<File>
The optional files associated with the request.
Implementations§
Source§impl Request
impl Request
Sourcepub fn try_from(
byte_stream: &[u8],
max_len: Option<usize>,
) -> Result<Self, RequestError>
pub fn try_from( byte_stream: &[u8], max_len: Option<usize>, ) -> Result<Self, RequestError>
Parses a byte slice into a HTTP Request.
The byte slice is expected to have the following format:
* Request Line: “GET SP Request-uri SP HTTP/1.0 CRLF” - Mandatory
* Request Headers “
§Errors
The function returns InvalidRequest when parsing the byte stream fails.
§Examples
use dbs_uhttp::Request;
let max_request_len = 2000;
let request_bytes = b"GET http://localhost/home HTTP/1.0\r\n\r\n";
let http_request = Request::try_from(request_bytes, Some(max_request_len)).unwrap();
Sourcepub fn uri(&self) -> &Uri
pub fn uri(&self) -> &Uri
Returns the Uri
from the parsed Request
.
The return value can be used to get the absolute path of the URI.
Sourcepub fn http_version(&self) -> Version
pub fn http_version(&self) -> Version
Returns the HTTP Version
of the Request
.