summaryrefslogtreecommitdiffstats
path: root/routers/common
diff options
context:
space:
mode:
Diffstat (limited to 'routers/common')
-rw-r--r--routers/common/repo.go20
1 files changed, 12 insertions, 8 deletions
diff --git a/routers/common/repo.go b/routers/common/repo.go
index 22403da097..8d33fb07fb 100644
--- a/routers/common/repo.go
+++ b/routers/common/repo.go
@@ -64,16 +64,26 @@ func ServeData(ctx *context.Context, name string, size int64, reader io.Reader)
st := typesniffer.DetectContentType(buf)
+ mappedMimeType := ""
+ if setting.MimeTypeMap.Enabled {
+ fileExtension := strings.ToLower(filepath.Ext(name))
+ mappedMimeType = setting.MimeTypeMap.Map[fileExtension]
+ }
if st.IsText() || ctx.QueryBool("render") {
cs, err := charset.DetectEncoding(buf)
if err != nil {
log.Error("Detect raw file %s charset failed: %v, using by default utf-8", name, err)
cs = "utf-8"
}
- ctx.Resp.Header().Set("Content-Type", "text/plain; charset="+strings.ToLower(cs))
+ if mappedMimeType == "" {
+ mappedMimeType = "text/plain"
+ }
+ ctx.Resp.Header().Set("Content-Type", mappedMimeType+"; charset="+strings.ToLower(cs))
} else {
ctx.Resp.Header().Set("Access-Control-Expose-Headers", "Content-Disposition")
-
+ if mappedMimeType != "" {
+ ctx.Resp.Header().Set("Content-Type", mappedMimeType)
+ }
if (st.IsImage() || st.IsPDF()) && (setting.UI.SVG.Enabled || !st.IsSvgImage()) {
ctx.Resp.Header().Set("Content-Disposition", fmt.Sprintf(`inline; filename="%s"`, name))
if st.IsSvgImage() {
@@ -83,12 +93,6 @@ func ServeData(ctx *context.Context, name string, size int64, reader io.Reader)
}
} else {
ctx.Resp.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, name))
- if setting.MimeTypeMap.Enabled {
- fileExtension := strings.ToLower(filepath.Ext(name))
- if mimetype, ok := setting.MimeTypeMap.Map[fileExtension]; ok {
- ctx.Resp.Header().Set("Content-Type", mimetype)
- }
- }
}
}