From 9cf756b188529edd215988bd7b23fd91fd691445 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sun, 31 Oct 2021 18:06:43 -0700 Subject: [PATCH] S3: support CORS related to https://github.com/chrislusf/seaweedfs/issues/1271 --- weed/s3api/s3err/error_handler.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/weed/s3api/s3err/error_handler.go b/weed/s3api/s3err/error_handler.go index 7e5e262a6..3cfdaafef 100644 --- a/weed/s3api/s3err/error_handler.go +++ b/weed/s3api/s3err/error_handler.go @@ -64,6 +64,10 @@ func EncodeXMLResponse(response interface{}) []byte { func setCommonHeaders(w http.ResponseWriter, r *http.Request) { w.Header().Set("x-amz-request-id", fmt.Sprintf("%d", time.Now().UnixNano())) w.Header().Set("Accept-Ranges", "bytes") + if r.Header.Get("Origin") != "" { + w.Header().Set("Access-Control-Allow-Origin", "*") + w.Header().Set("Access-Control-Allow-Credentials", "true") + } } func WriteResponse(w http.ResponseWriter, r *http.Request, statusCode int, response []byte, mType mimeType) {