inline PDFs, add filename quotes per MSDN

Signed-off-by: Matt Hamilton <m@tthamilton.com>
This commit is contained in:
Matt Hamilton 2022-08-08 16:27:57 -04:00
parent 0066bc5113
commit b767431d1e
No known key found for this signature in database
GPG key ID: 874D8969B12C4544

View file

@ -348,8 +348,13 @@ func (ctx *Context) RespHeader() http.Header {
// SetServeHeaders sets necessary content serve headers // SetServeHeaders sets necessary content serve headers
func (ctx *Context) SetServeHeaders(filename string) { func (ctx *Context) SetServeHeaders(filename string) {
ctx.Resp.Header().Set("Content-Description", "File Transfer") ctx.Resp.Header().Set("Content-Description", "File Transfer")
ctx.Resp.Header().Set("Content-Type", "application/octet-stream") if strings.HasSuffix(filename, ".pdf") {
ctx.Resp.Header().Set("Content-Disposition", "attachment; filename="+filename) ctx.Resp.Header().Set("Content-Disposition", "inline; filename=\""+filename+"\"")
ctx.Resp.Header().Set("Content-Type", "application/pdf")
} else {
ctx.Resp.Header().Set("Content-Type", "application/octet-stream")
ctx.Resp.Header().Set("Content-Disposition", "attachment; filename=\""+filename+"\"")
}
ctx.Resp.Header().Set("Content-Transfer-Encoding", "binary") ctx.Resp.Header().Set("Content-Transfer-Encoding", "binary")
ctx.Resp.Header().Set("Expires", "0") ctx.Resp.Header().Set("Expires", "0")
ctx.Resp.Header().Set("Cache-Control", "must-revalidate") ctx.Resp.Header().Set("Cache-Control", "must-revalidate")