Allow CopyObject in pathStyle across federated instances (#8064)

Fixes #7976
This commit is contained in:
Harshavardhana 2019-08-21 22:02:39 -10:00 committed by GitHub
parent cd03bfb3cf
commit f13f421e84
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 25 deletions

View file

@ -673,27 +673,30 @@ func (f bucketForwardingHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
bucket, _ = urlPath2BucketObjectName(r.URL.Path) bucket, _ = urlPath2BucketObjectName(r.URL.Path)
} }
} }
if bucket != "" { if bucket == "" {
sr, err := globalDNSConfig.Get(bucket) f.handler.ServeHTTP(w, r)
if err != nil { return
if err == dns.ErrNoEntriesFound { }
writeErrorResponse(context.Background(), w, errorCodes.ToAPIErr(ErrNoSuchBucket), r.URL, guessIsBrowserReq(r)) sr, err := globalDNSConfig.Get(bucket)
} else { if err != nil {
writeErrorResponse(context.Background(), w, toAPIError(context.Background(), err), r.URL, guessIsBrowserReq(r)) if err == dns.ErrNoEntriesFound {
} writeErrorResponse(context.Background(), w, errorCodes.ToAPIErr(ErrNoSuchBucket),
return r.URL, guessIsBrowserReq(r))
} } else {
if globalDomainIPs.Intersection(set.CreateStringSet(getHostsSlice(sr)...)).IsEmpty() { writeErrorResponse(context.Background(), w, toAPIError(context.Background(), err),
r.URL.Scheme = "http" r.URL, guessIsBrowserReq(r))
if globalIsSSL { }
r.URL.Scheme = "https" return
} }
r.URL.Host = getHostFromSrv(sr) if globalDomainIPs.Intersection(set.CreateStringSet(getHostsSlice(sr)...)).IsEmpty() {
f.fwd.ServeHTTP(w, r) r.URL.Scheme = "http"
return if globalIsSSL {
} r.URL.Scheme = "https"
}
r.URL.Host = getHostFromSrv(sr)
f.fwd.ServeHTTP(w, r)
return
} }
f.handler.ServeHTTP(w, r)
return return
} }
@ -715,9 +718,12 @@ func (f bucketForwardingHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
// CopyObject requests should be handled at current endpoint as path style // CopyObject requests should be handled at current endpoint as path style
// requests have target bucket and object in URI and source details are in // requests have target bucket and object in URI and source details are in
// header fields // header fields
if r.Method == http.MethodPut && r.Header.Get("X-Amz-Copy-Source") != "" { if r.Method == http.MethodPut && r.Header.Get(xhttp.AmzCopySource) != "" {
f.handler.ServeHTTP(w, r) bucket, object = urlPath2BucketObjectName(r.Header.Get(xhttp.AmzCopySource))
return if bucket == "" || object == "" {
f.handler.ServeHTTP(w, r)
return
}
} }
sr, err := globalDNSConfig.Get(bucket) sr, err := globalDNSConfig.Get(bucket)
if err != nil { if err != nil {

View file

@ -1063,7 +1063,7 @@ func (api objectAPIHandlers) PutObjectHandler(w http.ResponseWriter, r *http.Req
r.Body = &detectDisconnect{r.Body, r.Context().Done()} r.Body = &detectDisconnect{r.Body, r.Context().Done()}
// X-Amz-Copy-Source shouldn't be set for this call. // X-Amz-Copy-Source shouldn't be set for this call.
if _, ok := r.Header["X-Amz-Copy-Source"]; ok { if _, ok := r.Header[xhttp.AmzCopySource]; ok {
writeErrorResponse(ctx, w, errorCodes.ToAPIErr(ErrInvalidCopySource), r.URL, guessIsBrowserReq(r)) writeErrorResponse(ctx, w, errorCodes.ToAPIErr(ErrInvalidCopySource), r.URL, guessIsBrowserReq(r))
return return
} }
@ -1086,7 +1086,7 @@ func (api objectAPIHandlers) PutObjectHandler(w http.ResponseWriter, r *http.Req
size := r.ContentLength size := r.ContentLength
rAuthType := getRequestAuthType(r) rAuthType := getRequestAuthType(r)
if rAuthType == authTypeStreamingSigned { if rAuthType == authTypeStreamingSigned {
if sizeStr, ok := r.Header["X-Amz-Decoded-Content-Length"]; ok { if sizeStr, ok := r.Header[xhttp.AmzDecodedContentLength]; ok {
if sizeStr[0] == "" { if sizeStr[0] == "" {
writeErrorResponse(ctx, w, errorCodes.ToAPIErr(ErrMissingContentLength), r.URL, guessIsBrowserReq(r)) writeErrorResponse(ctx, w, errorCodes.ToAPIErr(ErrMissingContentLength), r.URL, guessIsBrowserReq(r))
return return