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

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.

Implementations

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

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

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.

Variant of make_bewit that takes a Duration (starting from now) instead of a SystemTime, provided for convenience.

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!

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.

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

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

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

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

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.