storj/storagenode/console/consoleserver/mime.go
Egon Elbre 9e5679fdaa storagenode/console/consoleserver: set content-type manually
http.FileServer relies on mime types defined in the operating system.
These values may be misconfigured, so a javascript file might
end up being served as "plain/text".

Change-Id: I3c13c8a9ac484bd765a4de0f8253bfe40dde7513
2020-02-03 15:37:47 +02:00

36 lines
926 B
Go

// Copyright (C) 2020 Storj Labs, Inc.
// See LICENSE for copying information.
package consoleserver
import "strings"
// CommonContentType returns content-type for common extensions.
func CommonContentType(ext string) (string, bool) {
ext = strings.ToLower(ext)
mime, ok := commonContentType[ext]
return mime, ok
}
var commonContentType = map[string]string{
".css": "text/css; charset=utf-8",
".gif": "image/gif",
".htm": "text/html; charset=utf-8",
".html": "text/html; charset=utf-8",
".jpeg": "image/jpeg",
".jpg": "image/jpeg",
".js": "application/javascript",
".mjs": "application/javascript",
".otf": "font/otf",
".pdf": "application/pdf",
".png": "image/png",
".svg": "image/svg+xml",
".ttf": "font/ttf",
".wasm": "application/wasm",
".webp": "image/webp",
".xml": "text/xml; charset=utf-8",
".sfnt": "font/sfnt",
".woff": "font/woff",
".woff2": "font/woff2",
}