|
|
@ -23,6 +23,7 @@ import ( |
|
|
|
"encoding/base64" |
|
|
|
"encoding/base64" |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
"io" |
|
|
|
"io" |
|
|
|
|
|
|
|
"net" |
|
|
|
"net/http" |
|
|
|
"net/http" |
|
|
|
"net/url" |
|
|
|
"net/url" |
|
|
|
"sort" |
|
|
|
"sort" |
|
|
@ -99,6 +100,7 @@ func getStringToSign(req *http.Request) string { |
|
|
|
buf.WriteByte('\n') |
|
|
|
buf.WriteByte('\n') |
|
|
|
writeCanonicalizedAmzHeaders(buf, req) |
|
|
|
writeCanonicalizedAmzHeaders(buf, req) |
|
|
|
writeCanonicalizedResource(buf, req) |
|
|
|
writeCanonicalizedResource(buf, req) |
|
|
|
|
|
|
|
|
|
|
|
return buf.String() |
|
|
|
return buf.String() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -188,14 +190,19 @@ func writeCanonicalizedResource(buf *bytes.Buffer, req *http.Request) { |
|
|
|
|
|
|
|
|
|
|
|
// Convert subdomain http request into bucketname if possible
|
|
|
|
// Convert subdomain http request into bucketname if possible
|
|
|
|
func bucketFromHostname(req *http.Request) string { |
|
|
|
func bucketFromHostname(req *http.Request) string { |
|
|
|
host := req.Host |
|
|
|
host, _, _ := net.SplitHostPort(req.Host) |
|
|
|
|
|
|
|
// Verify incoming request if only IP with no bucket subdomain
|
|
|
|
|
|
|
|
if net.ParseIP(host) != nil { |
|
|
|
|
|
|
|
return "" |
|
|
|
|
|
|
|
} |
|
|
|
if host == "" { |
|
|
|
if host == "" { |
|
|
|
host = req.URL.Host |
|
|
|
host = req.URL.Host |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Grab the bucket from the incoming hostname
|
|
|
|
host = strings.TrimSpace(host) |
|
|
|
host = strings.TrimSpace(host) |
|
|
|
hostParts := strings.Split(host, ".") |
|
|
|
hostParts := strings.Split(host, ".") |
|
|
|
if len(hostParts) > 1 { |
|
|
|
if len(hostParts) > 2 { |
|
|
|
return hostParts[0] |
|
|
|
return hostParts[0] |
|
|
|
} |
|
|
|
} |
|
|
|
return "" |
|
|
|
return "" |
|
|
|