Struct Request

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

The handshake request.

Implementations§

Source§

impl Request

Source

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

Get the value of the first instance of an HTTP header.

Source

pub fn header_mut(&mut self, header: &str) -> Option<&mut Vec<u8>>

Edit the value of the first instance of an HTTP header.

Source

pub fn headers(&self) -> &Vec<(String, Vec<u8>)>

Access the request headers.

Source

pub fn headers_mut(&mut self) -> &mut Vec<(String, Vec<u8>)>

Edit the request headers.

Source

pub fn origin(&self) -> Result<Option<&str>>

Get the origin of the request if it comes from a browser.

Source

pub fn key(&self) -> Result<&Vec<u8>>

Get the unhashed WebSocket key sent in the request.

Source

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

Get the hashed WebSocket key from this request.

Source

pub fn version(&self) -> Result<&str>

Get the WebSocket protocol version from the request (should be 13).

Source

pub fn resource(&self) -> &str

Get the path of the request.

Source

pub fn protocols(&self) -> Result<Vec<&str>>

Get the possible protocols for the WebSocket connection.

Source

pub fn add_protocol(&mut self, protocol: &str)

Add a possible protocol to this request. This may result in duplicate protocols listed.

Source

pub fn remove_protocol(&mut self, protocol: &str)

Remove a possible protocol from this request.

Source

pub fn extensions(&self) -> Result<Vec<&str>>

Get the possible extensions for the WebSocket connection.

Source

pub fn add_extension(&mut self, ext: &str)

Add a possible extension to this request. This may result in duplicate extensions listed. Also, the order of extensions indicates preference, so if the preference matters, consider using the Sec-WebSocket-Protocol header directly.

Source

pub fn remove_extension(&mut self, ext: &str)

Remove a possible extension from this request. This will remove all configurations of the extension.

Source

pub fn client_addr(&self) -> Result<Option<&str>>

Get the IP address of the client.

This method will attempt to retrieve the most likely IP address of the requester in the following manner:

If the X-Forwarded-For header exists, this method will return the left most address in the list.

If the Forwarded HTTP Header Field exits, this method will return the left most address indicated by the for parameter, if it exists.

§Note

This method does not ensure that the address is a valid IP address.

Source

pub fn parse(buf: &[u8]) -> Result<Option<Request>>

Attempt to parse an HTTP request from a buffer. If the buffer does not contain a complete request, this will return Ok(None).

Source

pub fn from_url(url: &Url) -> Result<Request>

Construct a new WebSocket handshake HTTP request from a url.

Source

pub fn format<W>(&self, w: &mut W) -> Result<()>
where W: Write,

Write a request out to a buffer

Trait Implementations§

Source§

impl Debug for Request

Source§

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

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

impl Display 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.