This commit is contained in:
Lea Anthony 2022-01-29 10:21:07 +11:00 committed by GitHub
commit 4a89508b50
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,7 +3,6 @@ package assetserver
import (
"net/http"
"path/filepath"
"strings"
"sync"
"github.com/gabriel-vasile/mimetype"
@ -18,6 +17,14 @@ func GetMimetype(filename string, data []byte) string {
mutex.Lock()
defer mutex.Unlock()
if filepath.Ext(filename) == ".js" {
return "application/javascript"
}
if filepath.Ext(filename) == ".css" {
return "text/css"
}
result := cache[filename]
if result != "" {
return result
@ -30,14 +37,6 @@ func GetMimetype(filename string, data []byte) string {
result = detect.String()
}
if filepath.Ext(filename) == ".css" && strings.HasPrefix(result, "text/plain") {
result = strings.Replace(result, "text/plain", "text/css", 1)
}
if filepath.Ext(filename) == ".js" && strings.HasPrefix(result, "text/plain") {
result = strings.Replace(result, "text/plain", "text/javascript", 1)
}
if result == "" {
result = "application/octet-stream"
}