Merge pull request #125 from harshavardhana/pr_out_add_key_and_bucket_name_handling_for_s3_properly
This commit is contained in:
+2
-3
@@ -223,7 +223,7 @@ var subResList = []string{"acl", "lifecycle", "location", "logging", "notificati
|
||||
// <HTTP-Request-URI, from the protocol name up to the query string> +
|
||||
// [ sub-resource, if present. For example "?acl", "?location", "?logging", or "?torrent"];
|
||||
func (a *Auth) writeCanonicalizedResource(buf *bytes.Buffer, req *http.Request, host string) {
|
||||
bucket := a.bucketFromEndpoint(req, host)
|
||||
bucket := a.bucketFromHost(req, host)
|
||||
if bucket != "" {
|
||||
buf.WriteByte('/')
|
||||
buf.WriteString(bucket)
|
||||
@@ -255,7 +255,7 @@ func hasDotSuffix(s string, suffix string) bool {
|
||||
return len(s) >= len(suffix)+1 && strings.HasSuffix(s, suffix) && s[len(s)-len(suffix)-1] == '.'
|
||||
}
|
||||
|
||||
func (a *Auth) bucketFromEndpoint(req *http.Request, host string) string {
|
||||
func (a *Auth) bucketFromHost(req *http.Request, host string) string {
|
||||
reqHost := req.Host
|
||||
if reqHost == "" {
|
||||
host = req.URL.Host
|
||||
@@ -274,6 +274,5 @@ func (a *Auth) bucketFromEndpoint(req *http.Request, host string) string {
|
||||
}
|
||||
|
||||
reqHost, _, _ = net.SplitHostPort(reqHost)
|
||||
|
||||
return reqHost
|
||||
}
|
||||
|
||||
+9
-1
@@ -124,7 +124,15 @@ func (c *Client) bucketURL(bucket string) string {
|
||||
}
|
||||
|
||||
func (c *Client) keyURL(bucket, key string) string {
|
||||
return c.bucketURL(bucket) + "/" + key
|
||||
url := c.bucketURL(bucket)
|
||||
if strings.Contains(c.Host, "localhost") || strings.Contains(c.Host, "127.0.0.1") {
|
||||
return url + "/" + key
|
||||
}
|
||||
host, _, _ := net.SplitHostPort(c.Host)
|
||||
if net.ParseIP(host) != nil {
|
||||
return url + "/" + key
|
||||
}
|
||||
return url + key
|
||||
}
|
||||
|
||||
func newReq(url string) *http.Request {
|
||||
|
||||
Reference in New Issue
Block a user