mirror of
https://github.com/gofiber/fiber.git
synced 2025-05-31 11:52:41 +00:00
⚡Improve ctx.Is performance
This commit is contained in:
parent
aafa784bbb
commit
1211b15b51
233
utils.go
233
utils.go
@ -573,236 +573,3 @@ const (
|
||||
HeaderXRobotsTag = "X-Robots-Tag"
|
||||
HeaderXUACompatible = "X-UA-Compatible"
|
||||
)
|
||||
|
||||
// MIME types were copied from https://github.com/nginx/nginx/blob/master/conf/mime.types
|
||||
func mimeExtensions(ext string) string {
|
||||
switch ext {
|
||||
case "html":
|
||||
return "text/html"
|
||||
case "htm":
|
||||
return "text/html"
|
||||
case "shtml":
|
||||
return "text/html"
|
||||
case "css":
|
||||
return "text/css"
|
||||
case "gif":
|
||||
return "image/gif"
|
||||
case "jpeg":
|
||||
return "image/jpeg"
|
||||
case "jpg":
|
||||
return "image/jpeg"
|
||||
case "xml":
|
||||
return "application/xml"
|
||||
case "js":
|
||||
return "application/javascript"
|
||||
case "atom":
|
||||
return "application/atom+xml"
|
||||
case "rss":
|
||||
return "application/rss+xml"
|
||||
case "mml":
|
||||
return "text/mathml"
|
||||
case "txt":
|
||||
return "text/plain"
|
||||
case "jad":
|
||||
return "text/vnd.sun.j2me.app-descriptor"
|
||||
case "wml":
|
||||
return "text/vnd.wap.wml"
|
||||
case "htc":
|
||||
return "text/x-component"
|
||||
case "png":
|
||||
return "image/png"
|
||||
case "svg":
|
||||
return "image/svg+xml"
|
||||
case "svgz":
|
||||
return "image/svg+xml"
|
||||
case "tif":
|
||||
return "image/tiff"
|
||||
case "tiff":
|
||||
return "image/tiff"
|
||||
case "wbmp":
|
||||
return "image/vnd.wap.wbmp"
|
||||
case "webp":
|
||||
return "image/webp"
|
||||
case "ico":
|
||||
return "image/x-icon"
|
||||
case "jng":
|
||||
return "image/x-jng"
|
||||
case "bmp":
|
||||
return "image/x-ms-bmp"
|
||||
case "woff":
|
||||
return "font/woff"
|
||||
case "woff2":
|
||||
return "font/woff2"
|
||||
case "jar":
|
||||
return "application/java-archive"
|
||||
case "war":
|
||||
return "application/java-archive"
|
||||
case "ear":
|
||||
return "application/java-archive"
|
||||
case "json":
|
||||
return "application/json"
|
||||
case "hqx":
|
||||
return "application/mac-binhex40"
|
||||
case "doc":
|
||||
return "application/msword"
|
||||
case "pdf":
|
||||
return "application/pdf"
|
||||
case "ps":
|
||||
return "application/postscript"
|
||||
case "eps":
|
||||
return "application/postscript"
|
||||
case "ai":
|
||||
return "application/postscript"
|
||||
case "rtf":
|
||||
return "application/rtf"
|
||||
case "m3u8":
|
||||
return "application/vnd.apple.mpegurl"
|
||||
case "kml":
|
||||
return "application/vnd.google-earth.kml+xml"
|
||||
case "kmz":
|
||||
return "application/vnd.google-earth.kmz"
|
||||
case "xls":
|
||||
return "application/vnd.ms-excel"
|
||||
case "eot":
|
||||
return "application/vnd.ms-fontobject"
|
||||
case "ppt":
|
||||
return "application/vnd.ms-powerpoint"
|
||||
case "odg":
|
||||
return "application/vnd.oasis.opendocument.graphics"
|
||||
case "odp":
|
||||
return "application/vnd.oasis.opendocument.presentation"
|
||||
case "ods":
|
||||
return "application/vnd.oasis.opendocument.spreadsheet"
|
||||
case "odt":
|
||||
return "application/vnd.oasis.opendocument.text"
|
||||
case "wmlc":
|
||||
return "application/vnd.wap.wmlc"
|
||||
case "7z":
|
||||
return "application/x-7z-compressed"
|
||||
case "cco":
|
||||
return "application/x-cocoa"
|
||||
case "jardiff":
|
||||
return "aplication/x-java-archive-diff"
|
||||
case "jnlp":
|
||||
return "application/x-java-jnlp-file"
|
||||
case "run":
|
||||
return "application/x-makeself"
|
||||
case "pl":
|
||||
return "application/x-perl"
|
||||
case "pm":
|
||||
return "application/x-perl"
|
||||
case "prc":
|
||||
return "application/x-pilot"
|
||||
case "pdb":
|
||||
return "application/x-pilot"
|
||||
case "rar":
|
||||
return "application/x-rar-compressed"
|
||||
case "rpm":
|
||||
return "application/x-redhat-package-manager"
|
||||
case "sea":
|
||||
return "application/x-sea"
|
||||
case "swf":
|
||||
return "application/x-shockwave-flash"
|
||||
case "sit":
|
||||
return "application/x-stuffit"
|
||||
case "tcl":
|
||||
return "application/x-tcl"
|
||||
case "tk":
|
||||
return "application/x-tcl"
|
||||
case "der":
|
||||
return "application/x-x509-ca-cert"
|
||||
case "pem":
|
||||
return "application/x-x509-ca-cert"
|
||||
case "crt":
|
||||
return "application/x-x509-ca-cert"
|
||||
case "xpi":
|
||||
return "application/x-xpinstall"
|
||||
case "xhtml":
|
||||
return "application/xhtml+xml"
|
||||
case "xspf":
|
||||
return "application/xspf+xml"
|
||||
case "zip":
|
||||
return "application/zip"
|
||||
case "bin":
|
||||
return "application/octet-stream"
|
||||
case "exe":
|
||||
return "application/octet-stream"
|
||||
case "dll":
|
||||
return "application/octet-stream"
|
||||
case "deb":
|
||||
return "application/octet-stream"
|
||||
case "dmg":
|
||||
return "application/octet-stream"
|
||||
case "iso":
|
||||
return "application/octet-stream"
|
||||
case "img":
|
||||
return "application/octet-stream"
|
||||
case "msi":
|
||||
return "application/octet-stream"
|
||||
case "msp":
|
||||
return "application/octet-stream"
|
||||
case "msm":
|
||||
return "application/octet-stream"
|
||||
case "mid":
|
||||
return "audio/midi"
|
||||
case "midi":
|
||||
return "audio/midi"
|
||||
case "kar":
|
||||
return "audio/midi"
|
||||
case "mp3":
|
||||
return "audio/mpeg"
|
||||
case "ogg":
|
||||
return "audio/ogg"
|
||||
case "m4a":
|
||||
return "audio/x-m4a"
|
||||
case "ra":
|
||||
return "audio/x-realaudio"
|
||||
case "3gpp":
|
||||
return "video/3gpp"
|
||||
case "3gp":
|
||||
return "video/3gpp"
|
||||
case "ts":
|
||||
return "video/mp2t"
|
||||
case "mp4":
|
||||
return "video/mp4"
|
||||
case "mpeg":
|
||||
return "video/mpeg"
|
||||
case "mpg":
|
||||
return "video/mpeg"
|
||||
case "mov":
|
||||
return "video/quicktime"
|
||||
case "webm":
|
||||
return "video/webm"
|
||||
case "flv":
|
||||
return "video/x-flv"
|
||||
case "m4v":
|
||||
return "video/x-m4v"
|
||||
case "mng":
|
||||
return "video/x-mng"
|
||||
case "asx":
|
||||
return "video/x-ms-asf"
|
||||
case "asf":
|
||||
return "video/x-ms-asf"
|
||||
case "wmv":
|
||||
return "video/x-ms-wmv"
|
||||
case "avi":
|
||||
return "video/x-msvideo"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// GetMIME returns the content-type of a file extension
|
||||
func GetMIME(extension string) (mime string) {
|
||||
if len(extension) == 0 {
|
||||
return mime
|
||||
}
|
||||
if extension[0] == '.' {
|
||||
mime = mimeExtensions(extension[1:])
|
||||
} else {
|
||||
mime = mimeExtensions(extension)
|
||||
}
|
||||
if len(mime) == 0 {
|
||||
return MIMEOctetStream
|
||||
}
|
||||
return mime
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user