mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
s3api: send user metadata headers in lowercase (#13228)
GET/HEAD returned user metadata as X-Amz-Meta-<key>. AWS sends x-amz-meta-<key>, and older aws-sdk-kotlin releases match the prefix case-sensitively, so they saw no metadata at all. Airbyte's S3 destination reads ab-generation-id that way at the end of an Overwrite sync, treats a missing id as generation 0, and deleted the files it had just written.
This commit is contained in:
1 parent
d6dee41f00
commit
abd2587f9e
2 files changed
+7
-12
No files matched your search
@@ -2546,17 +2546,11 @@ func (s3a *S3ApiServer) setResponseHeaders(w http.ResponseWriter, r *http.Reques
|
||||
if strings.HasPrefix(lowerKey, "xattr-") || strings.HasPrefix(lowerKey, extAmzPrefixLower) || strings.HasPrefix(lowerKey, taggingPrefixLower) || s3_constants.IsSeaweedFSInternalHeader(lowerKey) {
|
||||
continue
|
||||
}
|
||||
// Support backward compatibility: migrate old non-canonical format to canonical format
|
||||
// OLD: "x-amz-meta-foo" → NEW: "X-Amz-Meta-foo" (preserving suffix case)
|
||||
// AWS sends user metadata all lowercase, and some SDKs match the
|
||||
// x-amz-meta- prefix case-sensitively and drop anything else.
|
||||
headerKey := k
|
||||
if len(k) >= 11 && strings.EqualFold(k[:11], "x-amz-meta-") {
|
||||
// Normalize to AWS S3 format: "X-Amz-Meta-" prefix with lowercase suffix
|
||||
// AWS S3 returns user metadata with the suffix in lowercase
|
||||
suffix := k[len("x-amz-meta-"):]
|
||||
headerKey = s3_constants.AmzUserMetaPrefix + strings.ToLower(suffix)
|
||||
if glog.V(4) && k != headerKey {
|
||||
glog.Infof("Normalizing user metadata header %q to %q in response", k, headerKey)
|
||||
}
|
||||
if strings.HasPrefix(lowerKey, "x-amz-meta-") {
|
||||
headerKey = lowerKey
|
||||
}
|
||||
w.Header()[headerKey] = []string{string(v)}
|
||||
}
|
||||
|
||||
@@ -56,8 +56,9 @@ func TestSetResponseHeadersFiltersInternalExtendedKeys(t *testing.T) {
|
||||
if got := w.Header().Get(s3_constants.AmzTagCount); got != "2" {
|
||||
t.Errorf("%s: tag count = %q, want 2", method, got)
|
||||
}
|
||||
if got := w.Header()["X-Amz-Meta-foo"]; len(got) != 1 || got[0] != "bar" {
|
||||
t.Errorf("%s: user metadata dropped, X-Amz-Meta-foo = %v", method, got)
|
||||
// Raw map lookup: the wire name must be lowercase, as AWS sends it.
|
||||
if got := w.Header()["x-amz-meta-foo"]; len(got) != 1 || got[0] != "bar" {
|
||||
t.Errorf("%s: user metadata not sent as x-amz-meta-foo, headers = %v", method, w.Header())
|
||||
}
|
||||
if got := w.Header().Get("Cache-Control"); got != "no-cache" {
|
||||
t.Errorf("%s: Cache-Control = %q", method, got)
|
||||
|
||||
Reference in new issue
Block a user