http::request

Struct HttpRequest

Source
pub struct HttpRequest { /* private fields */ }
Expand description

HTTP Request

Represents an HTTP request

Implementations§

Source§

impl HttpRequest

Source§

impl HttpRequest

Source

pub fn parse(stream: impl Into<HttpStream>) -> Result<Self>

Read and parse an HTTP request from the given HttpStream

Source

pub fn keep_alive(self) -> Result<Self>

Source

pub fn stream(&self) -> &HttpStream

Source

pub fn url(&self) -> &str

Url of the request

Source

pub fn set_url(&mut self, url: impl Into<Box<str>>)

Source

pub fn params(&self) -> &HashMap<Box<str>, Box<str>>

Get the query parameters

Source

pub fn param(&self, key: &str) -> Option<&str>

Source

pub fn filename(&self) -> Result<Box<str>>

Get the filename for the request

It computes the path in the server corresponding to the request’s url.

Source

pub fn write_to(&self, f: &mut dyn Write) -> Result<()>

Source

pub fn send_to(&self, stream: HttpStream) -> Result<HttpResponse>

Sends the HttpRequest to a stream

§Errors

If the transfer fails, returns the error

Source

pub fn method(&self) -> &HttpMethod

Source

pub fn status(&self) -> u16

Source

pub fn set_status(&mut self, status: u16) -> &mut Self

Source

pub fn version(&self) -> f32

Source

pub fn content_length(&self) -> usize

Get the value of the Content-Length HTTP header

If the header is not present, or if it fails to parse it’s value, it returns 0

Source

pub fn header(&self, key: &str) -> Option<&str>

Get the value of the given header key, if present

Source

pub fn headers(&self) -> &HashMap<Box<str>, Box<str>>

Source

pub fn set_header( &mut self, key: impl Into<Box<str>>, value: impl Into<Box<str>>, )

Source

pub fn body(&mut self) -> Option<&[u8]>

Source

pub fn read_body(&mut self, writer: &mut dyn Write) -> Result<()>

Reads the request body into writer

§Errors

If, while reading of writing, some io Error is found

Source

pub fn respond(&mut self) -> Result<()>

Respond to the request without a body

§Errors

If some io error is produced while sending the request

Source

pub fn respond_buf(&mut self, buf: &[u8]) -> Result<()>

Respond to the request with the data of buf as a body

§Errors

If some io error is produced while sending the request

Source

pub fn respond_str(&mut self, text: &str) -> Result<()>

Respond to the request with the given string

§Errors

If some io error is produced while sending the request

Source

pub fn respond_reader(&mut self, reader: &mut dyn Read) -> Result<()>

Respond to the request with the data read from reader as a body

§Errors

If some io error is produced while sending the request

Source

pub fn respond_chunked(&mut self, reader: &mut dyn Read) -> Result<()>

Respond to the request as a chunked transfer

This means that the Content-Length of the request doen’t need to be known.

§Errors

If some io error is produced while sending the request

Source

pub fn respond_error_page(&mut self) -> Result<()>

Respond with a basic HTML error page

§Errors

If some io error is produced while sending the request

Source

pub fn ok(&mut self) -> Result<()>

Respond to the request with an 200 OK status

§Errors

If some io error is produced while sending the request

Source

pub fn forbidden(&mut self) -> Result<()>

Respond to the request with an 403 FORBIDDEN status

§Errors

If some io error is produced while sending the request

Source

pub fn unauthorized(&mut self) -> Result<()>

Respond to the request with an 401 UNAUTHORIZED status

§Errors

If some io error is produced while sending the request

Source

pub fn not_found(&mut self) -> Result<()>

Respond to the request with an 404 NOT FOUND status

§Errors

If some io error is produced while sending the request

Source

pub fn server_error(&mut self) -> Result<()>

Respond to the request with an 500 INTERNAL SERVER ERROR status

§Errors

If some io error is produced while sending the request

Source

pub fn is_http_ok(&self) -> bool

Source

pub fn is_http_err(&self) -> bool

Source

pub fn status_msg(&self) -> &'static str

Source

pub fn error_page(&self) -> String

Returns a basic HTML error page of the given status

Trait Implementations§

Source§

impl Debug for HttpRequest

Source§

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

Formats the value using the given formatter. Read more
Source§

impl PartialEq for HttpRequest

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

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.