From 7c6d8ca2229e06ab69ac6199f6116f99b4b70ea8 Mon Sep 17 00:00:00 2001 From: XZB Date: Thu, 2 Jun 2022 18:13:17 +0800 Subject: [PATCH] fix(proxy): filename is urlencoded when using Safari --- server/common/proxy.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/common/proxy.go b/server/common/proxy.go index e6a2174e5e8..ed8ee2c47d9 100644 --- a/server/common/proxy.go +++ b/server/common/proxy.go @@ -26,7 +26,7 @@ func Proxy(w http.ResponseWriter, r *http.Request, link *base.Link, file *model. _ = link.Data.Close() }() w.Header().Set("Content-Type", "application/octet-stream") - w.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename=%s`, file.Name)) + w.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"; filename*=UTF-8''%s`, file.Name, url.QueryEscape(file.Name))) w.Header().Set("Content-Length", strconv.FormatInt(file.Size, 10)) if link.Header != nil { for h, val := range link.Header { @@ -57,7 +57,7 @@ func Proxy(w http.ResponseWriter, r *http.Request, link *base.Link, file *model. if err != nil { return err } - w.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename=%s`, url.QueryEscape(file.Name))) + w.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"; filename*=UTF-8''%s`, file.Name, url.QueryEscape(file.Name))) http.ServeContent(w, r, file.Name, fileStat.ModTime(), f) return nil } else {