pub struct Request {
pub request_method: String,
pub uri: Uri,
pub headers: HeaderMap<HeaderValue>,
pub body: Option<Vec<u8>>,
}
Expand description
A data structure containing the elements of the request (some client-supplied, some service-supplied) involved in the SigV4 verification process.
This is typically populated from the HTTP request headers and body by using the
Request::from_http_request_parts
method.
Fields§
§request_method: String
The request method (GET, PUT, POST) (client).
uri: Uri
The URI path being accessed (client).
headers: HeaderMap<HeaderValue>
The HTTP headers sent with the request (client).
body: Option<Vec<u8>>
The request body (if any) (client).
Implementations§
Source§impl Request
impl Request
Sourcepub fn from_http_request_parts(parts: &Parts, body: Option<Vec<u8>>) -> Self
pub fn from_http_request_parts(parts: &Parts, body: Option<Vec<u8>>) -> Self
Create a Request from an HTTP request.
§Example
let http_req = http::Request::get("https://example.com")
.header("X-Amz-Date", "20210101T000000Z")
.body(())
.unwrap();
let req = Request::from_http_request_parts(&http_req.into_parts().0, None);
Sourcepub fn to_get_signing_key_request<A1, A2>(
&self,
signing_key_kind: SigningKeyKind,
region: A1,
service: A2,
) -> Result<GetSigningKeyRequest, SignatureError>
pub fn to_get_signing_key_request<A1, A2>( &self, signing_key_kind: SigningKeyKind, region: A1, service: A2, ) -> Result<GetSigningKeyRequest, SignatureError>
Returns a GetSigningKeyRequest
from this request.
This is used to request a signing key from an external source.
§Example
let gsk_req = req.to_get_signing_key_request(
SigningKeyKind::KSigning, "us-east-1", "example").unwrap();
assert_eq!(gsk_req.signing_key_kind, SigningKeyKind::KSigning);
assert_eq!(gsk_req.access_key, "AKIAIOSFODNN7EXAMPLE");
assert_eq!(gsk_req.request_date, NaiveDate::from_ymd_opt(2021, 1, 1).unwrap());
assert_eq!(gsk_req.region, "us-east-1");
assert_eq!(gsk_req.service, "example");
Sourcepub fn get_request_timestamp(&self) -> Result<DateTime<Utc>, SignatureError>
pub fn get_request_timestamp(&self) -> Result<DateTime<Utc>, SignatureError>
The timestamp of the request.
This returns the first value found from:
- The
X-Amz-Date
query parameter. - The
X-Amz-Date
HTTP header. - The
Date
HTTP header.
The timestamp should be in ISO 8601 YYYYMMDDTHHMMSSZ
format
without milliseconds (must per AWS documentation).
However, the AWS SigV4 test suite includes a variety of date formats,
including RFC 2822, RFC 3339, and ISO 8601. This routine allows all
of these formats.
This is unlikely to be useful in regular code; it is exposed for testing purposes.
§Errors
If the X-Amz-Date`` query parameter is present but is not a valid timestamp, [
SignatureError::MalformedParameter`] is returned.
If the X-Amz-Date
query parameter is missing and the X-Amz-Date
header is present but is not a valid
timestamp, SignatureError::MalformedHeader
is returned.
If the X-Amz-Date
query parameter and X-Amz-Date
header are missing and the Date
header is present
but is not a valid timestamp, SignatureError::MalformedHeader
is returned.
If none of the above are present, SignatureError::MissingHeader
is returned.
§Example
use chrono::{DateTime, NaiveDate, NaiveDateTime, NaiveTime, Utc};
use http::Request;
use scratchstack_aws_signature::Request as SigRequest;
let req = Request::get("https://example.com")
.header("X-Amz-Date", "20210101T000000Z")
.body(())
.unwrap();
let req = SigRequest::from_http_request_parts(&req.into_parts().0, None);
let expected = DateTime::<Utc>::from_naive_utc_and_offset(
NaiveDateTime::new(
NaiveDate::from_ymd_opt(2021, 1, 1).unwrap(),
NaiveTime::from_hms_opt(0, 0, 0).unwrap()),
Utc
);
assert_eq!(req.get_request_timestamp().unwrap(), expected);