diff options
| author | Chris Lu <chrislusf@users.noreply.github.com> | 2025-12-05 15:59:12 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-12-05 15:59:12 -0800 |
| commit | 89b6deaefa6e5f5f297237e9dfa82eb50c897349 (patch) | |
| tree | 738c88cc25e2aadd0a34a0e3f8dbf019bee55853 /weed/server/common.go | |
| parent | f1384108e8559e08d4c8c9dc4d7d12b61a79e0b5 (diff) | |
| download | seaweedfs-89b6deaefa6e5f5f297237e9dfa82eb50c897349.tar.xz seaweedfs-89b6deaefa6e5f5f297237e9dfa82eb50c897349.zip | |
fix: Use mime.FormatMediaType for RFC 6266 compliant Content-Disposition (#7635)
Updated Content-Disposition header generation to use mime.FormatMediaType
from the standard library, which properly handles non-ASCII characters
and special characters per RFC 6266.
Changes:
- weed/server/common.go: Updated adjustHeaderContentDisposition to use
mime.FormatMediaType instead of manual escaping with fileNameEscaper
- weed/operation/upload_content.go: Updated multipart form Content-Disposition
to use mime.FormatMediaType
- weed/server/volume_server_handlers_read.go: Removed unused fileNameEscaper
This ensures correct filename display for international users across
filer downloads and file uploads.
Fixes #7634
Diffstat (limited to 'weed/server/common.go')
| -rw-r--r-- | weed/server/common.go | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/weed/server/common.go b/weed/server/common.go index 930695f4b..dfed891b4 100644 --- a/weed/server/common.go +++ b/weed/server/common.go @@ -9,9 +9,9 @@ import ( "fmt" "io" "io/fs" + "mime" "mime/multipart" "net/http" - "net/url" "path/filepath" "strconv" "strings" @@ -286,14 +286,15 @@ func adjustHeaderContentDisposition(w http.ResponseWriter, r *http.Request, file return } if filename != "" { - filename = url.QueryEscape(filename) - contentDisposition := "inline" + dispositionType := "inline" if r.FormValue("dl") != "" { if dl, _ := strconv.ParseBool(r.FormValue("dl")); dl { - contentDisposition = "attachment" + dispositionType = "attachment" } } - w.Header().Set("Content-Disposition", contentDisposition+`; filename="`+fileNameEscaper.Replace(filename)+`"`) + // Use mime.FormatMediaType for RFC 6266 compliant Content-Disposition, + // properly handling non-ASCII characters and special characters + w.Header().Set("Content-Disposition", mime.FormatMediaType(dispositionType, map[string]string{"filename": filename})) } } |
