diff --git a/common.go b/common.go index c6eec00..d4bea47 100644 --- a/common.go +++ b/common.go @@ -45,6 +45,9 @@ func serviceAndRegion(host string) (service string, region string) { service = parts[0] region = parts[1] } + } else if len(parts) == 5 { + service = parts[2] + region = parts[1] } else { // Either service.amazonaws.com or s3-region.amazonaws.com if strings.HasPrefix(parts[0], "s3-") { diff --git a/sign4.go b/sign4.go index b5f3e59..89770bd 100644 --- a/sign4.go +++ b/sign4.go @@ -33,6 +33,16 @@ func hashedCanonicalRequestV4(request *http.Request, meta *metadata) string { var headersToSign string for _, key := range sortedHeaderKeys { value := strings.TrimSpace(request.Header.Get(key)) + if key == "host" { + //AWS does not include port in signing request. + if strings.Contains(value, ":") { + split := strings.Split(value, ":") + port := split[1] + if port == "80" || port == "443" { + value = split[0] + } + } + } headersToSign += key + ":" + value + "\n" } meta.signedHeaders = concat(";", sortedHeaderKeys...)