Request

Struct Request 

Source
pub struct Request<'a> { /* private fields */ }
Expand description

The Request type used by Oxide Auth to extract required information

Implementations§

Source§

impl<'a> Request<'a>

Source

pub fn new(inner: &'a Request) -> Self

Create a new Request from a rouille::Request

Methods from Deref<Target = Request>§

Source

pub fn remove_prefix(&self, prefix: &str) -> Option<Request>

If the decoded URL of the request starts with prefix, builds a new Request that is the same as the original but without that prefix.

§Example
fn handle(request: &Request) -> Response {
    if let Some(request) = request.remove_prefix("/static") {
        return rouille::match_assets(&request, "/static");
    }

    // ...
}
Source

pub fn is_secure(&self) -> bool

Returns true if the request uses HTTPS, and false if it uses HTTP.

§Example
use rouille::{Request, Response};

fn handle(request: &Request) -> Response {
    if !request.is_secure() {
        return Response::redirect_303(format!("https://example.com"));
    }

    // ...
}
Source

pub fn method(&self) -> &str

Returns the method of the request (GET, POST, etc.).

Source

pub fn raw_url(&self) -> &str

Returns the raw URL requested by the client. It is not decoded and thus can contain strings such as %20, and the query parameters such as ?p=hello.

See also url().

§Example
use rouille::Request;

let request = Request::fake_http("GET", "/hello%20world?foo=bar", vec![], vec![]);
assert_eq!(request.raw_url(), "/hello%20world?foo=bar");
Source

pub fn raw_query_string(&self) -> &str

Returns the raw query string requested by the client. In other words, everything after the first ? in the raw url.

Returns the empty string if no query string.

Source

pub fn url(&self) -> String

Returns the URL requested by the client.

Contrary to raw_url, special characters have been decoded and the query string (eg ?p=hello) has been removed.

If there is any non-unicode character in the URL, it will be replaced with U+FFFD.

Note: This function will decode the token %2F will be decoded as /. However the official specifications say that such a token must not count as a delimiter for URL paths. In other words, /hello/world is not the same as /hello%2Fworld.

§Example
use rouille::Request;

let request = Request::fake_http("GET", "/hello%20world?foo=bar", vec![], vec![]);
assert_eq!(request.url(), "/hello world");
Source

pub fn get_param(&self, param_name: &str) -> Option<String>

Returns the value of a GET parameter or None if it doesn’t exist.

Source

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

Returns the value of a header of the request.

Returns None if no such header could be found.

Source

pub fn headers(&self) -> HeadersIter<'_>

Returns a list of all the headers of the request.

Source

pub fn do_not_track(&self) -> Option<bool>

Returns the state of the DNT (Do Not Track) header.

If the header is missing or is malformed, None is returned. If the header exists, Some(true) is returned if DNT is 1 and Some(false) is returned if DNT is 0.

§Example
use rouille::{Request, Response};

fn handle(request: &Request) -> Response {
    if !request.do_not_track().unwrap_or(false) {
        track_user(&request);
    }

    // ...
}
Source

pub fn data(&self) -> Option<RequestBody<'_>>

Returns the body of the request.

The body can only be retrieved once. Returns None is the body has already been retrieved before.

§Example
use std::io::Read;
use rouille::{Request, Response, ResponseBody};

fn echo(request: &Request) -> Response {
    let mut data = request.data().expect("Oops, body already retrieved, problem \
                                          in the server");

    let mut buf = Vec::new();
    match data.read_to_end(&mut buf) {
        Ok(_) => (),
        Err(_) => return Response::text("Failed to read body")
    };

    Response {
        data: ResponseBody::from_data(buf),
        .. Response::text("")
    }
}
Source

pub fn remote_addr(&self) -> &SocketAddr

Returns the address of the client that made this request.

§Example
use rouille::{Request, Response};

fn handle(request: &Request) -> Response {
    Response::text(format!("Your IP is: {:?}", request.remote_addr()))
}

Trait Implementations§

Source§

impl<'a> Debug for Request<'a>

Source§

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

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

impl Deref for Request<'_>

Source§

type Target = Request

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<'a> WebRequest for Request<'a>

Source§

type Error = WebError

The error generated from access of malformed or invalid requests.
Source§

type Response = Response

The corresponding type of Responses returned from this module.
Source§

fn query( &mut self, ) -> Result<Cow<'_, dyn QueryParameter + 'static>, Self::Error>

Retrieve a parsed version of the url query. Read more
Source§

fn urlbody( &mut self, ) -> Result<Cow<'_, dyn QueryParameter + 'static>, Self::Error>

Retrieve the parsed application/x-form-urlencoded body of the request. Read more
Source§

fn authheader(&mut self) -> Result<Option<Cow<'_, str>>, Self::Error>

Contents of the authorization header or none if none exists. An Err value indicates a malformed header or request.

Auto Trait Implementations§

§

impl<'a> Freeze for Request<'a>

§

impl<'a> RefUnwindSafe for Request<'a>

§

impl<'a> Send for Request<'a>

§

impl<'a> Sync for Request<'a>

§

impl<'a> Unpin for Request<'a>

§

impl<'a> UnwindSafe for Request<'a>

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V