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

Backport #37552

Fix #37550

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Giteabot
2026-05-05 11:21:07 -07:00
committed by GitHub
parent 356a119f30
commit 58a66cae3c
2 changed files with 11 additions and 2 deletions
+8
View File
@@ -133,3 +133,11 @@ func TestServeSetHeaderContentRelated(t *testing.T) {
// make sure sandboxed
require.Contains(t, serveHeaderCspDefault, "; sandbox")
}
func TestServeSetHeaders(t *testing.T) {
w := httptest.NewRecorder()
ServeSetHeaders(w, ServeHeaderOptions{Filename: "foo.zip"})
assert.Equal(t, "attachment; filename=foo.zip", w.Header().Get("Content-Disposition"))
ServeSetHeaders(w, ServeHeaderOptions{Filename: "foo.zip", ContentDisposition: ContentDispositionInline})
assert.Equal(t, "inline; filename=foo.zip", w.Header().Get("Content-Disposition"))
}