Struct http_srv::request::HttpRequest

source ·
pub struct HttpRequest { /* private fields */ }
Expand description

HTTP Request

Represents an HTTP request

Implementations§

source§

impl HttpRequest

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§

impl HttpRequest

source

pub fn parse(stream: TcpStream) -> Result<Self>

Read and parse an HTTP request from the given TcpStream

source

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

source

pub fn stream(&self) -> &TcpStream

source

pub fn url(&self) -> &str

Url of the request

source

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

source

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

Get the query parameters

source

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

source

pub fn filename(&self) -> Result<String>

Get the filename for the request

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

source

pub fn method(&self) -> &RequestMethod

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<String, String>

source

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

source

pub fn body(&mut self) -> Vec<u8>

source

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

source

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

Respond to the request without a body

source

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

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

source

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

Respond to the request with the given string

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

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.

source

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

Respond with a basic HTML error page

source

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

Respond to the request with an 200 OK status

source

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

Respond to the request with an 403 FORBIDDEN status

source

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

Respond to the request with an 401 UNAUTHORIZED status

source

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

Respond to the request with an 404 NOT FOUND status

source

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

Respond to the request with an 500 INTERNAL SERVER ERROR status

source

pub fn error_page(&self) -> String

Returns a basic HTML error page of the given status

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>,

§

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>,

§

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.