diff options
| author | chrislu <chris.lu@gmail.com> | 2021-12-15 13:19:40 -0800 |
|---|---|---|
| committer | chrislu <chris.lu@gmail.com> | 2021-12-15 13:19:40 -0800 |
| commit | 8329cf86a795684038768223a05069fb247f815e (patch) | |
| tree | afab8d32b4a48fcaa0f85e5a06a6237872236b55 /weed/server | |
| parent | c63fff9a10c8cebc3346ff9bd6f498cc30d08140 (diff) | |
| parent | 7210558c7bb6efbd8377975918143478a14c5b3c (diff) | |
| download | seaweedfs-8329cf86a795684038768223a05069fb247f815e.tar.xz seaweedfs-8329cf86a795684038768223a05069fb247f815e.zip | |
Merge branch 'content_disposition_download'
Diffstat (limited to 'weed/server')
| -rw-r--r-- | weed/server/common.go | 16 | ||||
| -rw-r--r-- | weed/server/filer_server_handlers_read.go | 2 | ||||
| -rw-r--r-- | weed/server/volume_server_handlers_read.go | 2 |
3 files changed, 12 insertions, 8 deletions
diff --git a/weed/server/common.go b/weed/server/common.go index 16213689d..ba4d13456 100644 --- a/weed/server/common.go +++ b/weed/server/common.go @@ -5,6 +5,7 @@ import ( "encoding/json" "errors" "fmt" + xhttp "github.com/chrislusf/seaweedfs/weed/s3api/http" "io" "io/fs" "mime/multipart" @@ -250,13 +251,16 @@ func handleStaticResources2(r *mux.Router) { r.PathPrefix("/seaweedfsstatic/").Handler(http.StripPrefix("/seaweedfsstatic", http.FileServer(http.FS(StaticFS)))) } -func adjustHeaderContentDisposition(w http.ResponseWriter, r *http.Request, filename string) { - responseContentDisposition := r.FormValue("response-content-disposition") - if responseContentDisposition != "" { - w.Header().Set("Content-Disposition", responseContentDisposition) - return +func adjustPassthroughHeaders(w http.ResponseWriter, r *http.Request, filename string) { + for header, values := range r.Header { + if normalizedHeader, ok := xhttp.PassThroughHeaders[strings.ToLower(header)]; ok { + w.Header()[normalizedHeader] = values + } } - if w.Header().Get("Content-Disposition") != "" { + adjustHeaderContentDisposition(w, r, filename) +} +func adjustHeaderContentDisposition(w http.ResponseWriter, r *http.Request, filename string) { + if contentDisposition := w.Header().Get("Content-Disposition"); contentDisposition != "" { return } if filename != "" { diff --git a/weed/server/filer_server_handlers_read.go b/weed/server/filer_server_handlers_read.go index 86e4af586..ac6aea056 100644 --- a/weed/server/filer_server_handlers_read.go +++ b/weed/server/filer_server_handlers_read.go @@ -130,7 +130,7 @@ func (fs *FilerServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request) setEtag(w, etag) filename := entry.Name() - adjustHeaderContentDisposition(w, r, filename) + adjustPassthroughHeaders(w, r, filename) totalSize := int64(entry.Size()) diff --git a/weed/server/volume_server_handlers_read.go b/weed/server/volume_server_handlers_read.go index 5d12108d3..38cc10d62 100644 --- a/weed/server/volume_server_handlers_read.go +++ b/weed/server/volume_server_handlers_read.go @@ -301,7 +301,7 @@ func writeResponseContent(filename, mimeType string, rs io.ReadSeeker, w http.Re } w.Header().Set("Accept-Ranges", "bytes") - adjustHeaderContentDisposition(w, r, filename) + adjustPassthroughHeaders(w, r, filename) if r.Method == "HEAD" { w.Header().Set("Content-Length", strconv.FormatInt(totalSize, 10)) |
