From b767431d1eab0349d732194b65381765ae353792 Mon Sep 17 00:00:00 2001 From: Matt Hamilton Date: Mon, 8 Aug 2022 16:27:57 -0400 Subject: [PATCH] inline PDFs, add filename quotes per MSDN Signed-off-by: Matt Hamilton --- modules/context/context.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/context/context.go b/modules/context/context.go index 0b9898acef..0955258ea0 100644 --- a/modules/context/context.go +++ b/modules/context/context.go @@ -348,8 +348,13 @@ func (ctx *Context) RespHeader() http.Header { // SetServeHeaders sets necessary content serve headers func (ctx *Context) SetServeHeaders(filename string) { ctx.Resp.Header().Set("Content-Description", "File Transfer") - ctx.Resp.Header().Set("Content-Type", "application/octet-stream") - ctx.Resp.Header().Set("Content-Disposition", "attachment; filename="+filename) + if strings.HasSuffix(filename, ".pdf") { + 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("Expires", "0") ctx.Resp.Header().Set("Cache-Control", "must-revalidate")