Struct snowboard::Request

source ·
pub struct Request {
    pub ip: SocketAddr,
    pub url: String,
    pub method: Method,
    pub body: Vec<u8>,
    pub headers: HashMap<String, String>,
}
Expand description

A server request. Parses the raw request string into a more usable format.

Fields§

§ip: SocketAddr

The ip from the socket connection.

§url: String

Raw URL string. Use Request::parse_url() to get a parsed version of the URL

§method: Method

Method used in the request. Might be Method::Unknown if parsing fails.

§body: Vec<u8>

Body of the request, in bytes. Use Request::text, [Request::json], or [Request::force_json] to get a parsed version of the body.

§headers: HashMap<String, String>

Parsed headers.

Implementations§

source§

impl Request

source

pub fn new(bytes: &[u8], ip: SocketAddr) -> Option<Self>

Parses and creates a requeset from raw text and an ip address. Note that this does not parse the url (See Request::url).

source

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

Safely gets a header.

source

pub fn get_header_or(&self, key: &str, default: &'static str) -> &str

Equivalent to get_header(key).unwrap_or(default)

source

pub fn has_header(&self, key: &str) -> bool

Checks if a header exists.

source

pub fn set_header<T: ToString, K: ToString>(&mut self, k: T, v: K)

Sets a header using any key and value convertible to Strings

source

pub fn len(&self) -> usize

Gets the length of the body.

source

pub fn is_empty(&self) -> bool

Checks if the body is empty.

source

pub fn text(&self) -> Cow<'_, str>

Gets the body as a string. See String::from_utf8_lossy

source

pub fn parse_url(&self) -> Url<'_>

Get a parsed version of the URL. See Url

source

pub fn pretty_ip(&self) -> String

Get the IP address of the client, formatted.

Trait Implementations§

source§

impl Clone for Request

source§

fn clone(&self) -> Request

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Request

source§

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

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

impl PartialEq for Request

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for Request

source§

impl StructuralEq for Request

source§

impl StructuralPartialEq for Request

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.