added content-type serving exception tests

This commit is contained in:
Gani Georgiev
2026-05-05 11:40:07 +03:00
parent 8091a756e8
commit fe2d90641c
2 changed files with 84 additions and 9 deletions
+1 -1
View File
@@ -459,7 +459,7 @@ func (s *System) Serve(res http.ResponseWriter, req *http.Request, fileKey strin
// make an exception for specific content types and force a custom
// content type to send in the response so that it can be loaded properly
extContentType := realContentType
if ct, found := manualExtensionContentTypes[filepath.Ext(name)]; found {
if ct, found := manualExtensionContentTypes[filepath.Ext(fileKey)]; found {
extContentType = ct
}
+83 -8
View File
@@ -405,12 +405,12 @@ func TestFileSystemServe(t *testing.T) {
{
// svg exception
"image.svg",
"test_name.svg",
"test_name.abc",
nil,
nil,
false,
map[string]string{
"Content-Disposition": "attachment; filename=test_name.svg",
"Content-Disposition": "attachment; filename=test_name.abc",
"Content-Type": "image/svg+xml",
"Content-Length": "0",
"Content-Security-Policy": csp,
@@ -420,12 +420,12 @@ func TestFileSystemServe(t *testing.T) {
{
// css exception
"style.css",
"test_name.css",
"test_name",
nil,
nil,
false,
map[string]string{
"Content-Disposition": "attachment; filename=test_name.css",
"Content-Disposition": "attachment; filename=test_name",
"Content-Type": "text/css",
"Content-Length": "0",
"Content-Security-Policy": csp,
@@ -435,12 +435,12 @@ func TestFileSystemServe(t *testing.T) {
{
// js exception
"main.js",
"test_name.js",
"test_name.abc",
nil,
nil,
false,
map[string]string{
"Content-Disposition": "attachment; filename=test_name.js",
"Content-Disposition": "attachment; filename=test_name.abc",
"Content-Type": "text/javascript",
"Content-Length": "0",
"Content-Security-Policy": csp,
@@ -450,18 +450,63 @@ func TestFileSystemServe(t *testing.T) {
{
// mjs exception
"main.mjs",
"test_name.mjs",
"test_name.abc",
nil,
nil,
false,
map[string]string{
"Content-Disposition": "attachment; filename=test_name.mjs",
"Content-Disposition": "attachment; filename=test_name.abc",
"Content-Type": "text/javascript",
"Content-Length": "0",
"Content-Security-Policy": csp,
"Cache-Control": cacheControl,
},
},
{
// xlsx exception
"dummy.xlsx",
"test_name.abc",
nil,
nil,
false,
map[string]string{
"Content-Disposition": "attachment; filename=test_name.abc",
"Content-Type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"Content-Length": "0",
"Content-Security-Policy": csp,
"Cache-Control": cacheControl,
},
},
{
// docx exception
"dummy.docx",
"test_name.abc",
nil,
nil,
false,
map[string]string{
"Content-Disposition": "attachment; filename=test_name.abc",
"Content-Type": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"Content-Length": "0",
"Content-Security-Policy": csp,
"Cache-Control": cacheControl,
},
},
{
// pptx exception
"dummy.pptx",
"test_name.abc",
nil,
nil,
false,
map[string]string{
"Content-Disposition": "attachment; filename=test_name.abc",
"Content-Type": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
"Content-Length": "0",
"Content-Security-Policy": csp,
"Cache-Control": cacheControl,
},
},
{
// custom header
"test/sub2.txt",
@@ -716,6 +761,9 @@ func TestFileSystemList(t *testing.T) {
"style.css",
"main.js",
"main.mjs",
"dummy.xlsx",
"dummy.docx",
"dummy.pptx",
"test/sub1.txt",
"test/sub2.txt",
},
@@ -1041,5 +1089,32 @@ func createTestDir(t *testing.T) string {
file.Close()
}
// "docx" (we are interested only in the extension)
{
file, err := os.OpenFile(filepath.Join(dir, "dummy.docx"), os.O_WRONLY|os.O_CREATE, 0644)
if err != nil {
t.Fatal(err)
}
file.Close()
}
// "xlsx" (we are interested only in the extension)
{
file, err := os.OpenFile(filepath.Join(dir, "dummy.xlsx"), os.O_WRONLY|os.O_CREATE, 0644)
if err != nil {
t.Fatal(err)
}
file.Close()
}
// "pptx" (we are interested only in the extension)
{
file, err := os.OpenFile(filepath.Join(dir, "dummy.pptx"), os.O_WRONLY|os.O_CREATE, 0644)
if err != nil {
t.Fatal(err)
}
file.Close()
}
return dir
}