s3: pass through s3 presigned headers
fix https://github.com/chrislusf/seaweedfs/discussions/2502
This commit is contained in:
@@ -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 != "" {
|
||||
|
||||
@@ -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())
|
||||
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user