changed not to encode path when s3 request
@@ -360,6 +360,13 @@ impl SignedRequest {
// build the canonical request
let signed_headers = signed_headers(&self.headers);
self.canonical_uri = canonical_uri(&self.path);
+ // Normalize URI paths according to RFC 3986. Remove redundant and relative path components. Each path segment must be URI-encoded twice (except for Amazon S3 which only gets URI-encoded once).
+ // see https://docs.aws.amazon.com/general/latest/gr/sigv4-create-canonical-request.html
+ let canonical_uri = if &self.service != "s3" {
+ utf8_percent_encode(&self.canonical_uri, StrictPathEncodeSet).collect::<String>()
+ }else{
+ self.canonical_uri.clone()
+ };
let canonical_headers = canonical_headers(&self.headers);
let canonical_request: String;
@@ -368,7 +375,7 @@ impl SignedRequest {
None => {
canonical_request = format!("{}\n{}\n{}\n{}\n{}\n{}",
&self.method,
- utf8_percent_encode(&self.canonical_uri, StrictPathEncodeSet).collect::<String>(),
+ canonical_uri,
self.canonical_query_string,
canonical_headers,
signed_headers,
@@ -379,7 +386,7 @@ impl SignedRequest {
let (digest, len) = digest_payload(&payload);
canonical_request = format!("{}\n{}\n{}\n{}\n{}\n{}",
&self.method,
- utf8_percent_encode(&self.canonical_uri, StrictPathEncodeSet).collect::<String>(),
+ canonical_uri,
self.canonical_query_string,
canonical_headers,
signed_headers,
@@ -389,7 +396,7 @@ impl SignedRequest {
Some(SignedRequestPayload::Stream(len, _)) => {
canonical_request = format!("{}\n{}\n{}\n{}\n{}\n{}",
&self.method,
- utf8_percent_encode(&self.canonical_uri, StrictPathEncodeSet).collect::<String>(),
+ canonical_uri,
self.canonical_query_string,
canonical_headers,
signed_headers,
