mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
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>
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
@@ -0,0 +1,2 @@
|
||||
x<01><>K
|
||||
<EFBFBD>0Eg<15>%<25><>":u<><16>J|<7C><><EFBFBD><EFBFBD><1E><>p˭<70>Q<EFBFBD><51>~%
|
Binary file not shown.
Binary file not shown.
@@ -1 +1 @@
|
||||
205ac761f3326a7ebe416e8673760016450b5cec
|
||||
1032bbf17fbc0d9c95bb5418dabe8f8c99278700
|
||||
|
Reference in New Issue
Block a user