Skip to content
This repository has been archived by the owner on Aug 14, 2018. It is now read-only.

Commit

Permalink
Fixes for S3 signature generation.
Browse files Browse the repository at this point in the history
1. Don't bother with Content-MD5 if header is not specified.
2. Handle URLs with Opaque part (from aws-sdk-go).
  • Loading branch information
smira committed Mar 20, 2016
1 parent f78c76c commit 0070896
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ func stringToSignS3(request *http.Request) string {

if request.Header.Get("Content-Md5") != "" {
str += request.Header.Get("Content-Md5")
} else {
body := readAndReplaceBody(request)
if len(body) > 0 {
str += hashMD5(body)
}
}
str += "\n"

Expand Down Expand Up @@ -86,7 +81,17 @@ func canonicalResourceS3(request *http.Request) string {
res += "/" + bucketname
}

res += request.URL.Path
uri := request.URL.Opaque
if uri != "" {
uri = "/" + strings.Join(strings.Split(uri, "/")[3:], "/")
} else {
uri = request.URL.Path
}
if uri == "" {
uri = "/"
}

res += uri

for _, subres := range strings.Split(subresourcesS3, ",") {
if strings.HasPrefix(request.URL.RawQuery, subres) {
Expand Down

0 comments on commit 0070896

Please sign in to comment.