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§
source§impl<'a> Request<'a>
impl<'a> Request<'a>
sourcepub fn make_header(&self, credentials: &Credentials) -> Result<Header>
pub fn make_header(&self, credentials: &Credentials) -> Result<Header>
Create a new Header for this request, inventing a new nonce and setting the timestamp to the current time.
sourcepub fn make_header_full<S>(
&self,
credentials: &Credentials,
ts: SystemTime,
nonce: S
) -> Result<Header>
pub fn make_header_full<S>( &self, credentials: &Credentials, ts: SystemTime, nonce: S ) -> Result<Header>
Similar to make_header
, but allowing specification of the timestamp
and nonce.
sourcepub fn make_bewit(
&self,
credentials: &'a Credentials,
exp: SystemTime
) -> Result<Bewit<'a>>
pub fn make_bewit( &self, credentials: &'a Credentials, exp: SystemTime ) -> Result<Bewit<'a>>
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.
sourcepub fn make_bewit_with_ttl(
&self,
credentials: &'a Credentials,
ttl: Duration
) -> Result<Bewit<'a>>
pub fn make_bewit_with_ttl( &self, credentials: &'a Credentials, ttl: Duration ) -> Result<Bewit<'a>>
Variant of make_bewit
that takes a Duration (starting from now)
instead of a SystemTime, provided for convenience.
sourcepub fn validate_header(
&self,
header: &Header,
key: &Key,
ts_skew: Duration
) -> bool
pub fn validate_header( &self, header: &Header, key: &Key, ts_skew: Duration ) -> bool
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!
sourcepub fn validate_bewit(&self, bewit: &Bewit<'_>, key: &Key) -> bool
pub fn validate_bewit(&self, bewit: &Bewit<'_>, key: &Key) -> bool
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.
sourcepub fn make_response_builder(
&'a self,
req_header: &'a Header
) -> ResponseBuilder<'a>
pub fn make_response_builder( &'a self, req_header: &'a Header ) -> ResponseBuilder<'a>
Get a Response instance for a response to this request. This is a convenience
wrapper around Response::from_request_header
.