Make ServeSetHeaders default to download attachment if filename exists (#37552)

Fix #37550
This commit is contained in:
wxiaoguang
2026-05-06 00:41:49 +08:00
committed by GitHub
parent ee803ad05d
commit a5fd8e7e86
2 changed files with 11 additions and 2 deletions
+3 -2
View File
@@ -87,8 +87,9 @@ func ServeSetHeaders(w http.ResponseWriter, opts ServeHeaderOptions) {
if opts.ContentLength != nil {
header.Set("Content-Length", strconv.FormatInt(*opts.ContentLength, 10))
}
if opts.Filename != "" && opts.ContentDisposition != "" {
header.Set("Content-Disposition", encodeContentDisposition(opts.ContentDisposition, path.Base(opts.Filename)))
if opts.Filename != "" {
contentDisposition := util.IfZero(opts.ContentDisposition, ContentDispositionAttachment)
header.Set("Content-Disposition", encodeContentDisposition(contentDisposition, path.Base(opts.Filename)))
header.Set("Access-Control-Expose-Headers", "Content-Disposition")
}