summaryrefslogtreecommitdiffstats
path: root/integrations/download_test.go
diff options
context:
space:
mode:
authorJimmy Praet <jimmy.praet@telenet.be>2021-06-30 23:31:54 +0200
committerGitHub <noreply@github.com>2021-06-30 17:31:54 -0400
commitce286f9d9c00ceb24fb4eab4cab56c0b0678765a (patch)
treee8ef0385b108332f63bb744e45fe2ad62bb5a3cf /integrations/download_test.go
parent99799832835aae6a8641112cb71eb87baef32afa (diff)
downloadgitea-ce286f9d9c00ceb24fb4eab4cab56c0b0678765a.tar.gz
gitea-ce286f9d9c00ceb24fb4eab4cab56c0b0678765a.zip
Support custom mime type mapping for text files (#16304)
* Support custom mime type mapping for text files * Apply suggested change to routers/common/repo.go Co-authored-by: KN4CK3R <admin@oldschoolhack.me> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
Diffstat (limited to 'integrations/download_test.go')
-rw-r--r--integrations/download_test.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/integrations/download_test.go b/integrations/download_test.go
index 305155e9ac..38de75f476 100644
--- a/integrations/download_test.go
+++ b/integrations/download_test.go
@@ -8,6 +8,7 @@ import (
"net/http"
"testing"
+ "code.gitea.io/gitea/modules/setting"
"github.com/stretchr/testify/assert"
)
@@ -62,3 +63,30 @@ func TestDownloadByIDMediaForSVGUsesSecureHeaders(t *testing.T) {
assert.Equal(t, "image/svg+xml", resp.HeaderMap.Get("Content-Type"))
assert.Equal(t, "nosniff", resp.HeaderMap.Get("X-Content-Type-Options"))
}
+
+func TestDownloadRawTextFileWithoutMimeTypeMapping(t *testing.T) {
+ defer prepareTestEnv(t)()
+
+ session := loginUser(t, "user2")
+
+ req := NewRequest(t, "GET", "/user2/repo2/raw/branch/master/test.xml")
+ resp := session.MakeRequest(t, req, http.StatusOK)
+
+ assert.Equal(t, "text/plain; charset=utf-8", resp.HeaderMap.Get("Content-Type"))
+}
+
+func TestDownloadRawTextFileWithMimeTypeMapping(t *testing.T) {
+ defer prepareTestEnv(t)()
+ setting.MimeTypeMap.Map[".xml"] = "text/xml"
+ setting.MimeTypeMap.Enabled = true
+
+ session := loginUser(t, "user2")
+
+ req := NewRequest(t, "GET", "/user2/repo2/raw/branch/master/test.xml")
+ resp := session.MakeRequest(t, req, http.StatusOK)
+
+ assert.Equal(t, "text/xml; charset=utf-8", resp.HeaderMap.Get("Content-Type"))
+
+ delete(setting.MimeTypeMap.Map, ".xml")
+ setting.MimeTypeMap.Enabled = false
+}