Skip to content

Commit

Permalink
Preserve ETag case for S3 compatibility (minio#7498)
Browse files Browse the repository at this point in the history
Most hadoop distributions hortonworks, cloudera all
depend on aws-sdk-java 1.7.x to 1.10.x - the releases
which have bugs related case sensitive check for
ETag header. Go changes the case of the headers set
to be canonical but only preserves them when set
through a direct map.

This fixes most compatibility issues we have had
in the past supporting older hadoop distributions.
  • Loading branch information
harshavardhana authored and kannappanr committed Apr 8, 2019
1 parent 10a6071 commit a2e344b
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 9 deletions.
3 changes: 2 additions & 1 deletion cmd/api-headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func setObjectHeaders(w http.ResponseWriter, objInfo ObjectInfo, rs *HTTPRangeSp

// Set Etag if available.
if objInfo.ETag != "" {
w.Header().Set("ETag", "\""+objInfo.ETag+"\"")
w.Header()["ETag"] = []string{"\"" + objInfo.ETag + "\""}
}

if objInfo.ContentType != "" {
Expand All @@ -90,6 +90,7 @@ func setObjectHeaders(w http.ResponseWriter, objInfo ObjectInfo, rs *HTTPRangeSp
if !objInfo.Expires.IsZero() {
w.Header().Set("Expires", objInfo.Expires.UTC().Format(http.TimeFormat))
}

// Set all other user defined metadata.
for k, v := range objInfo.UserDefined {
if hasPrefix(k, ReservedMetadataPrefix) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/bucket-handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ func (api objectAPIHandlers) PostPolicyBucketHandler(w http.ResponseWriter, r *h
}

location := getObjectLocation(r, globalDomainNames, bucket, object)
w.Header().Set("ETag", `"`+objInfo.ETag+`"`)
w.Header()["ETag"] = []string{`"` + objInfo.ETag + `"`}
w.Header().Set("Location", location)

// Notify object created event.
Expand Down
4 changes: 2 additions & 2 deletions cmd/object-handlers-common.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func checkCopyObjectPreconditions(ctx context.Context, w http.ResponseWriter, r
w.Header().Set("Last-Modified", objInfo.ModTime.UTC().Format(http.TimeFormat))

if objInfo.ETag != "" {
w.Header().Set("ETag", "\""+objInfo.ETag+"\"")
w.Header()["ETag"] = []string{"\"" + objInfo.ETag + "\""}
}
}
// x-amz-copy-source-if-modified-since: Return the object only if it has been modified
Expand Down Expand Up @@ -166,7 +166,7 @@ func checkPreconditions(ctx context.Context, w http.ResponseWriter, r *http.Requ
w.Header().Set("Last-Modified", objInfo.ModTime.UTC().Format(http.TimeFormat))

if objInfo.ETag != "" {
w.Header().Set("ETag", "\""+objInfo.ETag+"\"")
w.Header()["ETag"] = []string{"\"" + objInfo.ETag + "\""}
}
}
// If-Modified-Since : Return the object only if it has been modified since the specified time,
Expand Down
6 changes: 3 additions & 3 deletions cmd/object-handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,7 @@ func (api objectAPIHandlers) PutObjectHandler(w http.ResponseWriter, r *http.Req
} else if hasServerSideEncryptionHeader(r.Header) {
etag = getDecryptedETag(r.Header, objInfo, false)
}
w.Header().Set("ETag", "\""+etag+"\"")
w.Header()["ETag"] = []string{"\"" + etag + "\""}

if objectAPI.IsEncryptionSupported() {
if crypto.IsEncrypted(objInfo.UserDefined) {
Expand Down Expand Up @@ -1941,7 +1941,7 @@ func (api objectAPIHandlers) PutObjectPartHandler(w http.ResponseWriter, r *http
} else if isEncrypted {
etag = tryDecryptETag(objectEncryptionKey, partInfo.ETag, crypto.SSEC.IsRequested(r.Header))
}
w.Header().Set("ETag", "\""+etag+"\"")
w.Header()["ETag"] = []string{"\"" + etag + "\""}

writeSuccessResponseHeadersOnly(w)
}
Expand Down Expand Up @@ -2304,7 +2304,7 @@ func (api objectAPIHandlers) CompleteMultipartUploadHandler(w http.ResponseWrite
}

// Set etag.
w.Header().Set("ETag", "\""+objInfo.ETag+"\"")
w.Header()["ETag"] = []string{"\"" + objInfo.ETag + "\""}

// Write success response.
writeSuccessResponseXML(w, encodedSuccessResponse)
Expand Down
2 changes: 1 addition & 1 deletion cmd/test-utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2413,7 +2413,7 @@ func uploadTestObject(t *testing.T, apiRouter http.Handler, creds auth.Credentia
rec = httptest.NewRecorder()
apiRouter.ServeHTTP(rec, req)
checkRespErr(rec, http.StatusOK)
etag := rec.Header().Get("ETag")
etag := rec.Header()["ETag"][0]
if etag == "" {
t.Fatalf("Unexpected empty etag")
}
Expand Down
2 changes: 1 addition & 1 deletion staticcheck.conf
Original file line number Diff line number Diff line change
@@ -1 +1 @@
checks = ["all", "-ST1005", "-ST1000", "-SA4000", "-SA9004", "-SA1019"]
checks = ["all", "-ST1005", "-ST1000", "-SA4000", "-SA9004", "-SA1019", "-SA1008"]

0 comments on commit a2e344b

Please sign in to comment.