Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

S3: Add `Vary` header for non-wildcard AllowOrigin (#7547)

粒粒橙a24c31de0609
diff --git a/weed/s3api/cors/cors.go b/weed/s3api/cors/cors.go
index d6eb520af0..ac9e7cca39 100644
--- a/weed/s3api/cors/cors.go
+++ b/weed/s3api/cors/cors.go
@@ -361,6 +361,10 @@ func ApplyHeaders(w http.ResponseWriter, corsResp *CORSResponse) {
if corsResp.AllowOrigin != "" {
w.Header().Set("Access-Control-Allow-Origin", corsResp.AllowOrigin)
+
+ if corsResp.AllowOrigin != "*" {
+ w.Header().Add("Vary", "Origin")
+ }
}
if corsResp.AllowMethods != "" {
diff --git a/weed/s3api/cors/cors_test.go b/weed/s3api/cors/cors_test.go
index 1b5c540284..8494a284d4 100644
--- a/weed/s3api/cors/cors_test.go
+++ b/weed/s3api/cors/cors_test.go
@@ -480,6 +480,7 @@ func TestApplyHeaders(t *testing.T) {
"Access-Control-Allow-Headers": "Content-Type",
"Access-Control-Expose-Headers": "ETag",
"Access-Control-Max-Age": "3600",
+ "Vary": "Origin",
},
},
{
@@ -493,6 +494,7 @@ func TestApplyHeaders(t *testing.T) {
"Access-Control-Allow-Origin": "http://example.com",
"Access-Control-Allow-Methods": "GET",
"Access-Control-Allow-Credentials": "true",
+ "Vary": "Origin",
},
},
}