Backport #37552 Fix #37550 Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -87,8 +87,9 @@ func ServeSetHeaders(w http.ResponseWriter, opts ServeHeaderOptions) {
|
|||||||
if opts.ContentLength != nil {
|
if opts.ContentLength != nil {
|
||||||
header.Set("Content-Length", strconv.FormatInt(*opts.ContentLength, 10))
|
header.Set("Content-Length", strconv.FormatInt(*opts.ContentLength, 10))
|
||||||
}
|
}
|
||||||
if opts.Filename != "" && opts.ContentDisposition != "" {
|
if opts.Filename != "" {
|
||||||
header.Set("Content-Disposition", encodeContentDisposition(opts.ContentDisposition, path.Base(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")
|
header.Set("Access-Control-Expose-Headers", "Content-Disposition")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -133,3 +133,11 @@ func TestServeSetHeaderContentRelated(t *testing.T) {
|
|||||||
// make sure sandboxed
|
// make sure sandboxed
|
||||||
require.Contains(t, serveHeaderCspDefault, "; sandbox")
|
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"))
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user