[][src]Struct hawk::Request

pub struct Request<'a> { /* fields omitted */ }

Request represents a single HTTP request.

The structure is created using (RequestBuilder)[struct.RequestBuilder.html]. Most uses of this library will hold several of the fields in this structure fixed. Cloning the structure with these fields applied is a convenient way to avoid repeating those fields. Most fields are references, since in common use the values already exist and will outlive the request.

A request can be used on the client, to generate a header or a bewit, or on the server, to validate the same.

Examples

use hawk::RequestBuilder;
let bldr = RequestBuilder::new("GET", "mysite.com", 443, "/");
let request1 = bldr.clone().method("POST").path("/api/user").request();
let request2 = bldr.path("/api/users").request();

See the documentation in the crate root for examples of creating and validating headers.

Methods

impl<'a> Request<'a>[src]

pub fn make_header(&self, credentials: &Credentials) -> Result<Header>[src]

Create a new Header for this request, inventing a new nonce and setting the timestamp to the current time.

pub fn make_header_full<S>(
    &self,
    credentials: &Credentials,
    ts: Timespec,
    nonce: S
) -> Result<Header> where
    S: Into<String>, 
[src]

Similar to make_header, but allowing specification of the timestamp and nonce.

pub fn make_bewit(
    &self,
    credentials: &'a Credentials,
    ttl: Duration
) -> Result<Bewit<'a>>
[src]

Make a "bewit" that can be attached to a URL to authenticate GET access.

The ttl gives the time for which this bewit is valid, starting now.

pub fn validate_header(
    &self,
    header: &Header,
    key: &Key,
    ts_skew: Duration
) -> bool
[src]

Validate the given header. This validates that the mac field matches that calculated using the other header fields and the given request information.

The header's timestamp is verified to be within ts_skew of the current time. If any of the required header fields are missing, the method will return false.

It is up to the caller to examine the header's id field and supply the corresponding key.

If desired, it is up to the caller to validate that nonce has not been used before.

If a hash has been supplied, then the header must contain a matching hash. Note that this hash must be calculated based on the request body, not copied from the request header!

pub fn validate_bewit(&self, bewit: &Bewit, key: &Key) -> bool[src]

Validate the given bewit matches this request.

It is up to the caller to consult the Bewit's id and look up the corresponding key.

Nonces and hashes do not apply when using bewits.

pub fn make_response_builder(
    &self,
    req_header: &'a Header
) -> ResponseBuilder<'a>
[src]

Get a Response instance for a response to this request. This is a convenience wrapper around Response::from_request_header.

Trait Implementations

impl<'a> Clone for Request<'a>[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl<'a> Debug for Request<'a>[src]

Auto Trait Implementations

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

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

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]