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.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
filer: add CORS support
Chris Lu306062b4e7ca
diff --git a/weed/server/filer_server_handlers.go b/weed/server/filer_server_handlers.goindex 18f78881c5..3f2946339a 100644--- a/weed/server/filer_server_handlers.go+++ b/weed/server/filer_server_handlers.go@@ -10,6 +10,10 @@ import (func (fs *FilerServer) filerHandler(w http.ResponseWriter, r *http.Request) {w.Header().Set("Server", "SeaweedFS Filer "+util.VERSION)+ if r.Header.Get("Origin") != "" {+ w.Header().Set("Access-Control-Allow-Origin", "*")+ w.Header().Set("Access-Control-Allow-Credentials", "true")+ }start := time.Now()switch r.Method {case "GET":@@ -32,11 +36,19 @@ func (fs *FilerServer) filerHandler(w http.ResponseWriter, r *http.Request) {stats.FilerRequestCounter.WithLabelValues("post").Inc()fs.PostHandler(w, r)stats.FilerRequestHistogram.WithLabelValues("post").Observe(time.Since(start).Seconds())+ case "OPTIONS":+ stats.FilerRequestCounter.WithLabelValues("options").Inc()+ OptionsHandler(w, r, false)+ stats.FilerRequestHistogram.WithLabelValues("head").Observe(time.Since(start).Seconds())}}func (fs *FilerServer) readonlyFilerHandler(w http.ResponseWriter, r *http.Request) {w.Header().Set("Server", "SeaweedFS Filer "+util.VERSION)+ if r.Header.Get("Origin") != "" {+ w.Header().Set("Access-Control-Allow-Origin", "*")+ w.Header().Set("Access-Control-Allow-Credentials", "true")+ }start := time.Now()switch r.Method {case "GET":@@ -47,5 +59,18 @@ func (fs *FilerServer) readonlyFilerHandler(w http.ResponseWriter, r *http.Requestats.FilerRequestCounter.WithLabelValues("head").Inc()fs.GetOrHeadHandler(w, r, false)stats.FilerRequestHistogram.WithLabelValues("head").Observe(time.Since(start).Seconds())+ case "OPTIONS":+ stats.FilerRequestCounter.WithLabelValues("options").Inc()+ OptionsHandler(w, r, true)+ stats.FilerRequestHistogram.WithLabelValues("head").Observe(time.Since(start).Seconds())}}++func OptionsHandler(w http.ResponseWriter, r *http.Request, isReadOnly bool) {+ if isReadOnly {+ w.Header().Add("Access-Control-Allow-Methods", "GET, OPTIONS")+ } else {+ w.Header().Add("Access-Control-Allow-Methods", "PUT, POST, GET, DELETE, OPTIONS")+ }+ w.Header().Add("Access-Control-Allow-Headers", "*")+}\ No newline at end of filediff --git a/weed/server/volume_server_handlers.go b/weed/server/volume_server_handlers.goindex 6f44b9a0a7..7852c950ab 100644--- a/weed/server/volume_server_handlers.go+++ b/weed/server/volume_server_handlers.go@@ -44,7 +44,8 @@ func (vs *VolumeServer) privateStoreHandler(w http.ResponseWriter, r *http.Requevs.guard.WhiteList(vs.PostHandler)(w, r)case "OPTIONS":stats.ReadRequest()- vs.guard.WhiteList(vs.OptionsHandler)(w, r)+ w.Header().Add("Access-Control-Allow-Methods", "PUT, POST, GET, DELETE, OPTIONS")+ w.Header().Add("Access-Control-Allow-Headers", "*")}}@@ -63,7 +64,8 @@ func (vs *VolumeServer) publicReadOnlyHandler(w http.ResponseWriter, r *http.Reqvs.GetOrHeadHandler(w, r)case "OPTIONS":stats.ReadRequest()- vs.OptionsHandler(w, r)+ w.Header().Add("Access-Control-Allow-Methods", "GET, OPTIONS")+ w.Header().Add("Access-Control-Allow-Headers", "*")}}diff --git a/weed/server/volume_server_handlers_read.go b/weed/server/volume_server_handlers_read.goindex 909b674a4c..15fd446e72 100644--- a/weed/server/volume_server_handlers_read.go+++ b/weed/server/volume_server_handlers_read.go@@ -270,10 +270,3 @@ func writeResponseContent(filename, mimeType string, rs io.ReadSeeker, w http.Re})return nil}--func (vs *VolumeServer) OptionsHandler(w http.ResponseWriter, r *http.Request) {- w.Header().Add("Access-Control-Allow-Origin", "*")- w.Header().Add("Access-Control-Allow-Methods", "PUT, POST, GET, DELETE, OPTIONS")- w.Header().Add("Access-Control-Allow-Headers", "Content-Type")- w.Header().Add("Access-Control-Allow-Credentials", "true")-}\ No newline at end of file