From 7c747a9643e3d46d6f637a8d4f8c49df9e7910ef Mon Sep 17 00:00:00 2001 From: kannappanr <30541348+kannappanr@users.noreply.github.com> Date: Fri, 23 Mar 2018 13:46:57 -0700 Subject: [PATCH] Return complete Location URL in CompleteMultipartUpload (#5692) Remove getLocation function. Fixes #5687 --- cmd/api-response.go | 9 ++++----- cmd/bucket-handlers.go | 2 +- cmd/object-handlers.go | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/cmd/api-response.go b/cmd/api-response.go index 5ae58e5ad..b252616e5 100644 --- a/cmd/api-response.go +++ b/cmd/api-response.go @@ -268,11 +268,6 @@ type PostResponse struct { Location string } -// getLocation get URL location. -func getLocation(r *http.Request) string { - return path.Clean(r.URL.Path) // Clean any trailing slashes. -} - // returns "https" if the tls boolean is true, "http" otherwise. func getURLScheme(tls bool) string { if tls { @@ -283,6 +278,10 @@ func getURLScheme(tls bool) string { // getObjectLocation gets the fully qualified URL of an object. func getObjectLocation(r *http.Request, domain, bucket, object string) string { + // unit tests do not have host set. + if r.Host == "" { + return path.Clean(r.URL.Path) + } proto := handlers.GetSourceScheme(r) if proto == "" { proto = getURLScheme(globalIsSSL) diff --git a/cmd/bucket-handlers.go b/cmd/bucket-handlers.go index 53da10989..5354f622f 100644 --- a/cmd/bucket-handlers.go +++ b/cmd/bucket-handlers.go @@ -430,7 +430,7 @@ func (api objectAPIHandlers) PutBucketHandler(w http.ResponseWriter, r *http.Req } // Make sure to add Location information here only for bucket - w.Header().Set("Location", getLocation(r)) + w.Header().Set("Location", path.Clean(r.URL.Path)) // Clean any trailing slashes. writeSuccessResponseHeadersOnly(w) } diff --git a/cmd/object-handlers.go b/cmd/object-handlers.go index 486def878..8b05d1716 100644 --- a/cmd/object-handlers.go +++ b/cmd/object-handlers.go @@ -1312,7 +1312,7 @@ func (api objectAPIHandlers) CompleteMultipartUploadHandler(w http.ResponseWrite } // Get object location. - location := getLocation(r) + location := getObjectLocation(r, globalDomainName, bucket, object) // Generate complete multipart response. response := generateCompleteMultpartUploadResponse(bucket, object, location, objInfo.ETag) encodedSuccessResponse := encodeResponse(response)