mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-19 18:39:30 +08:00
[v2] CSS mimetype fix
This commit is contained in:
parent
e4d70f94b1
commit
b54a94135d
@ -2,6 +2,8 @@ package assetserver
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
import "github.com/gabriel-vasile/mimetype"
|
||||
@ -27,6 +29,10 @@ 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 result == "" {
|
||||
result = "application/octet-stream"
|
||||
}
|
||||
|
25
v2/internal/frontend/assetserver/mimecache_test.go
Normal file
25
v2/internal/frontend/assetserver/mimecache_test.go
Normal file
@ -0,0 +1,25 @@
|
||||
package assetserver
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestGetMimetype(t *testing.T) {
|
||||
type args struct {
|
||||
filename string
|
||||
data []byte
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want string
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
{"css", args{"test.css", []byte("body{margin:0;padding:0;background-color:#d579b2}#app{font-family:Avenir,Helvetica,Arial,sans-serif;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;text-align:center;color:#2c3e50;background-color:#ededed}#nav{padding:30px}#nav a{font-weight:700;color:#2c\n3e50}#nav a.router-link-exact-active{color:#42b983}.hello[data-v-4e26ad49]{margin:10px 0}")}, "text/css; charset=utf-8"},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := GetMimetype(tt.args.filename, tt.args.data); got != tt.want {
|
||||
t.Errorf("GetMimetype() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user