mirror of
https://github.com/safing/portmaster
synced 2025-09-01 10:09:11 +00:00
Move MimeTypeByExtension to portbase/utils
This commit is contained in:
parent
5f387aba80
commit
028939b7ec
3 changed files with 6 additions and 74 deletions
2
go.mod
2
go.mod
|
@ -22,7 +22,7 @@ require (
|
|||
github.com/mitchellh/go-server-timing v1.0.1
|
||||
github.com/oschwald/maxminddb-golang v1.12.0
|
||||
github.com/safing/jess v0.3.1
|
||||
github.com/safing/portbase v0.18.3
|
||||
github.com/safing/portbase v0.18.4
|
||||
github.com/safing/portmaster-android/go v0.0.0-20230830120134-3226ceac3bec
|
||||
github.com/safing/spn v0.7.2
|
||||
github.com/shirou/gopsutil v3.21.11+incompatible
|
||||
|
|
2
go.sum
2
go.sum
|
@ -251,6 +251,8 @@ github.com/safing/portbase v0.15.2/go.mod h1:5bHi99fz7Hh/wOsZUOI631WF9ePSHk57c4f
|
|||
github.com/safing/portbase v0.16.2/go.mod h1:mzNCWqPbO7vIYbbK5PElGbudwd2vx4YPNawymL8Aro8=
|
||||
github.com/safing/portbase v0.18.3 h1:0eWv9r3in0MQEUaOyrd2LNhYKs+D6UZbys2fWTpO0+Y=
|
||||
github.com/safing/portbase v0.18.3/go.mod h1:qhhLjrr5iEGU9r7RZ6hJdtulOeycJ0d0jq95ZxGJ9Hs=
|
||||
github.com/safing/portbase v0.18.4 h1:Dinjp7EMe/McPwg0OcgoXdcjvQdO3yP85mhJQ8z7vOU=
|
||||
github.com/safing/portbase v0.18.4/go.mod h1:qhhLjrr5iEGU9r7RZ6hJdtulOeycJ0d0jq95ZxGJ9Hs=
|
||||
github.com/safing/portmaster-android/go v0.0.0-20230830120134-3226ceac3bec h1:oSJY1seobofPwpMoJRkCgXnTwfiQWNfGMCPDfqgAEfg=
|
||||
github.com/safing/portmaster-android/go v0.0.0-20230830120134-3226ceac3bec/go.mod h1:abwyAQrZGemWbSh/aCD9nnkp0SvFFf/mGWkAbOwPnFE=
|
||||
github.com/safing/spn v0.7.2 h1:FKxcGqWZaOr12Ddz+rSZi9KTu6H9N911FpVZJUh6eDc=
|
||||
|
|
76
ui/serve.go
76
ui/serve.go
|
@ -17,6 +17,7 @@ import (
|
|||
"github.com/safing/portbase/log"
|
||||
"github.com/safing/portbase/modules"
|
||||
"github.com/safing/portbase/updater"
|
||||
"github.com/safing/portbase/utils"
|
||||
"github.com/safing/portmaster/updates"
|
||||
)
|
||||
|
||||
|
@ -146,10 +147,8 @@ func ServeFileFromArchive(w http.ResponseWriter, r *http.Request, archiveName st
|
|||
// set content type
|
||||
_, ok := w.Header()["Content-Type"]
|
||||
if !ok {
|
||||
contentType := mimeTypeByExtension(filepath.Ext(path))
|
||||
if contentType != "" {
|
||||
w.Header().Set("Content-Type", contentType)
|
||||
}
|
||||
contentType, _ := utils.MimeTypeByExtension(filepath.Ext(path))
|
||||
w.Header().Set("Content-Type", contentType)
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
@ -178,72 +177,3 @@ func redirectToDefault(w http.ResponseWriter, r *http.Request) {
|
|||
func redirAddSlash(w http.ResponseWriter, r *http.Request) {
|
||||
http.Redirect(w, r, r.RequestURI+"/", http.StatusPermanentRedirect)
|
||||
}
|
||||
|
||||
// We now do our mimetypes ourselves, because, as far as we analyzed, a Windows
|
||||
// update screwed us over here and broke all the mime typing.
|
||||
// (April 2021)
|
||||
|
||||
var (
|
||||
defaultMimeType = "application/octet-stream"
|
||||
|
||||
mimeTypes = map[string]string{
|
||||
".7z": "application/x-7z-compressed",
|
||||
".atom": "application/atom+xml",
|
||||
".css": "text/css; charset=utf-8",
|
||||
".csv": "text/csv; charset=utf-8",
|
||||
".deb": "application/x-debian-package",
|
||||
".epub": "application/epub+zip",
|
||||
".es": "application/ecmascript",
|
||||
".flv": "video/x-flv",
|
||||
".gif": "image/gif",
|
||||
".gz": "application/gzip",
|
||||
".htm": "text/html; charset=utf-8",
|
||||
".html": "text/html; charset=utf-8",
|
||||
".jpeg": "image/jpeg",
|
||||
".jpg": "image/jpeg",
|
||||
".js": "text/javascript; charset=utf-8",
|
||||
".json": "application/json; charset=utf-8",
|
||||
".m3u": "audio/mpegurl",
|
||||
".m4a": "audio/mpeg",
|
||||
".md": "text/markdown; charset=utf-8",
|
||||
".mjs": "text/javascript; charset=utf-8",
|
||||
".mov": "video/quicktime",
|
||||
".mp3": "audio/mpeg",
|
||||
".mp4": "video/mp4",
|
||||
".mpeg": "video/mpeg",
|
||||
".mpg": "video/mpeg",
|
||||
".ogg": "audio/ogg",
|
||||
".ogv": "video/ogg",
|
||||
".otf": "font/otf",
|
||||
".pdf": "application/pdf",
|
||||
".png": "image/png",
|
||||
".qt": "video/quicktime",
|
||||
".rar": "application/rar",
|
||||
".rtf": "application/rtf",
|
||||
".svg": "image/svg+xml",
|
||||
".tar": "application/x-tar",
|
||||
".tiff": "image/tiff",
|
||||
".ts": "video/MP2T",
|
||||
".ttc": "font/collection",
|
||||
".ttf": "font/ttf",
|
||||
".txt": "text/plain; charset=utf-8",
|
||||
".wasm": "application/wasm",
|
||||
".wav": "audio/x-wav",
|
||||
".webm": "video/webm",
|
||||
".webp": "image/webp",
|
||||
".woff": "font/woff",
|
||||
".woff2": "font/woff2",
|
||||
".xml": "text/xml; charset=utf-8",
|
||||
".xz": "application/x-xz",
|
||||
".zip": "application/zip",
|
||||
}
|
||||
)
|
||||
|
||||
func mimeTypeByExtension(ext string) string {
|
||||
mimeType, ok := mimeTypes[ext]
|
||||
if ok {
|
||||
return mimeType
|
||||
}
|
||||
|
||||
return defaultMimeType
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue