fix(server/files): fix Content-Disposition is not set (#46)

* fix(server/files): fix Content-Disposition is not set

* test(header): check content disposition header
This commit is contained in:
Hexxa 2021-04-21 11:38:59 +08:00 committed by GitHub
parent a9ccb4506c
commit 8b5a80f766
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 23 additions and 7 deletions

View file

@ -396,9 +396,13 @@ func (h *FileHandlers) Download(c *gin.Context) {
}
// reader will be closed by multipart response writer
extraHeaders := map[string]string{
"Content-Disposition": fmt.Sprintf(`attachment; filename="%s"`, info.Name()),
}
// respond to normal requests
if ifRangeVal != "" || rangeVal == "" {
c.DataFromReader(200, info.Size(), contentType, r, map[string]string{})
c.DataFromReader(200, info.Size(), contentType, r, extraHeaders)
return
}
@ -417,9 +421,6 @@ func (h *FileHandlers) Download(c *gin.Context) {
go mw.Write()
extraHeaders := map[string]string{
"Content-Disposition": fmt.Sprintf(`attachment; filename="%s"`, info.Name()),
}
// it takes the \r\n before body into account, so contentLength+2
c.DataFromReader(206, contentLength+2, contentType, mw, extraHeaders)
}