diff options
author | Adam Szatyin <szatyinadam@gmail.com> | 2021-05-10 22:38:08 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-10 16:38:08 -0400 |
commit | d86d12332269c0d8b13ab2ea70c688640e44946e (patch) | |
tree | ce6ba2d457a53894ee1e73896417f8bbe59232ca /routers | |
parent | 2f65c6b2f03d4b8908422e63788d8775b5d64a8f (diff) | |
download | gitea-d86d12332269c0d8b13ab2ea70c688640e44946e.tar.gz gitea-d86d12332269c0d8b13ab2ea70c688640e44946e.zip |
Add mimetype mapping settings (#15133)
* Fix APK's Content-Type header
* Fix case sensitive comparison
* Add custom mime type mapping for downloadable files
* Add documentation for MIME type mapping
* Rename download.mimetype.mapping configuration to repository.mimetype_mapping
Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'routers')
-rw-r--r-- | routers/repo/download.go | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/routers/repo/download.go b/routers/repo/download.go index dafa62d0d9..4917c233ae 100644 --- a/routers/repo/download.go +++ b/routers/repo/download.go @@ -9,6 +9,7 @@ import ( "fmt" "io" "path" + "path/filepath" "strings" "code.gitea.io/gitea/modules/base" @@ -18,6 +19,7 @@ import ( "code.gitea.io/gitea/modules/httpcache" "code.gitea.io/gitea/modules/lfs" "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/setting" ) // ServeData download file from io.Reader @@ -61,6 +63,12 @@ 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)) ctx.Resp.Header().Set("Access-Control-Expose-Headers", "Content-Disposition") + 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) + } + } } _, err = ctx.Resp.Write(buf) |