Struct Request

Source
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

Source

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 “ CRLF”- Optional
* Empty Line “CRLF”
* Entity Body - Optional
The request headers and the entity body are not parsed and None is returned because these are not used by the MMDS server. The only supported method is GET and the HTTP protocol is expected to be HTTP/1.0 or HTTP/1.1.

§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();
Source

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.

Source

pub fn http_version(&self) -> Version

Returns the HTTP Version of the Request.

Source

pub fn method(&self) -> Method

Returns the HTTP Method of the Request.

Trait Implementations§

Source§

impl Debug for Request

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.