mirror of
https://github.com/gofiber/fiber.git
synced 2025-02-21 20:13:22 +00:00
213 lines
6.2 KiB
Go
213 lines
6.2 KiB
Go
// ⚡️ Fiber is an Express inspired web framework written in Go with ☕️
|
|
// 🤖 Github Repository: https://github.com/gofiber/fiber
|
|
// 📌 API Documentation: https://docs.gofiber.io
|
|
|
|
package utils
|
|
|
|
const MIMEOctetStream = "application/octet-stream"
|
|
|
|
// 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
|
|
}
|
|
|
|
// limits for HTTP statuscodes
|
|
const (
|
|
statusMessageMin = 100
|
|
statusMessageMax = 511
|
|
)
|
|
|
|
// StatusMessage returns the correct message for the provided HTTP statuscode
|
|
func StatusMessage(status int) string {
|
|
if status < statusMessageMin || status > statusMessageMax {
|
|
return ""
|
|
}
|
|
return statusMessage[status]
|
|
}
|
|
|
|
// HTTP status codes were copied from net/http.
|
|
var statusMessage = []string{
|
|
100: "Continue",
|
|
101: "Switching Protocols",
|
|
102: "Processing",
|
|
103: "Early Hints",
|
|
200: "OK",
|
|
201: "Created",
|
|
202: "Accepted",
|
|
203: "Non-Authoritative Information",
|
|
204: "No Content",
|
|
205: "Reset Content",
|
|
206: "Partial Content",
|
|
207: "Multi-Status",
|
|
208: "Already Reported",
|
|
226: "IM Used",
|
|
300: "Multiple Choices",
|
|
301: "Moved Permanently",
|
|
302: "Found",
|
|
303: "See Other",
|
|
304: "Not Modified",
|
|
305: "Use Proxy",
|
|
306: "Switch Proxy",
|
|
307: "Temporary Redirect",
|
|
308: "Permanent Redirect",
|
|
400: "Bad Request",
|
|
401: "Unauthorized",
|
|
402: "Payment Required",
|
|
403: "Forbidden",
|
|
404: "Not Found",
|
|
405: "Method Not Allowed",
|
|
406: "Not Acceptable",
|
|
407: "Proxy Authentication Required",
|
|
408: "Request Timeout",
|
|
409: "Conflict",
|
|
410: "Gone",
|
|
411: "Length Required",
|
|
412: "Precondition Failed",
|
|
413: "Request Entity Too Large",
|
|
414: "Request URI Too Long",
|
|
415: "Unsupported Media Type",
|
|
416: "Requested Range Not Satisfiable",
|
|
417: "Expectation Failed",
|
|
418: "I'm a teapot",
|
|
421: "Misdirected Request",
|
|
422: "Unprocessable Entity",
|
|
423: "Locked",
|
|
424: "Failed Dependency",
|
|
426: "Upgrade Required",
|
|
428: "Precondition Required",
|
|
429: "Too Many Requests",
|
|
431: "Request Header Fields Too Large",
|
|
451: "Unavailable For Legal Reasons",
|
|
500: "Internal Server Error",
|
|
501: "Not Implemented",
|
|
502: "Bad Gateway",
|
|
503: "Service Unavailable",
|
|
504: "Gateway Timeout",
|
|
505: "HTTP Version Not Supported",
|
|
506: "Variant Also Negotiates",
|
|
507: "Insufficient Storage",
|
|
508: "Loop Detected",
|
|
510: "Not Extended",
|
|
511: "Network Authentication Required",
|
|
}
|
|
|
|
// MIME types were copied from https://github.com/nginx/nginx/blob/master/conf/mime.types
|
|
var mimeExtensions = map[string]string{
|
|
"html": "text/html",
|
|
"htm": "text/html",
|
|
"shtml": "text/html",
|
|
"css": "text/css",
|
|
"gif": "image/gif",
|
|
"jpeg": "image/jpeg",
|
|
"jpg": "image/jpeg",
|
|
"xml": "application/xml",
|
|
"js": "application/javascript",
|
|
"atom": "application/atom+xml",
|
|
"rss": "application/rss+xml",
|
|
"mml": "text/mathml",
|
|
"txt": "text/plain",
|
|
"jad": "text/vnd.sun.j2me.app-descriptor",
|
|
"wml": "text/vnd.wap.wml",
|
|
"htc": "text/x-component",
|
|
"png": "image/png",
|
|
"svg": "image/svg+xml",
|
|
"svgz": "image/svg+xml",
|
|
"tif": "image/tiff",
|
|
"tiff": "image/tiff",
|
|
"wbmp": "image/vnd.wap.wbmp",
|
|
"webp": "image/webp",
|
|
"ico": "image/x-icon",
|
|
"jng": "image/x-jng",
|
|
"bmp": "image/x-ms-bmp",
|
|
"woff": "font/woff",
|
|
"woff2": "font/woff2",
|
|
"jar": "application/java-archive",
|
|
"war": "application/java-archive",
|
|
"ear": "application/java-archive",
|
|
"json": "application/json",
|
|
"hqx": "application/mac-binhex40",
|
|
"doc": "application/msword",
|
|
"pdf": "application/pdf",
|
|
"ps": "application/postscript",
|
|
"eps": "application/postscript",
|
|
"ai": "application/postscript",
|
|
"rtf": "application/rtf",
|
|
"m3u8": "application/vnd.apple.mpegurl",
|
|
"kml": "application/vnd.google-earth.kml+xml",
|
|
"kmz": "application/vnd.google-earth.kmz",
|
|
"xls": "application/vnd.ms-excel",
|
|
"eot": "application/vnd.ms-fontobject",
|
|
"ppt": "application/vnd.ms-powerpoint",
|
|
"odg": "application/vnd.oasis.opendocument.graphics",
|
|
"odp": "application/vnd.oasis.opendocument.presentation",
|
|
"ods": "application/vnd.oasis.opendocument.spreadsheet",
|
|
"odt": "application/vnd.oasis.opendocument.text",
|
|
"wmlc": "application/vnd.wap.wmlc",
|
|
"7z": "application/x-7z-compressed",
|
|
"cco": "application/x-cocoa",
|
|
"jardiff": "application/x-java-archive-diff",
|
|
"jnlp": "application/x-java-jnlp-file",
|
|
"run": "application/x-makeself",
|
|
"pl": "application/x-perl",
|
|
"pm": "application/x-perl",
|
|
"prc": "application/x-pilot",
|
|
"pdb": "application/x-pilot",
|
|
"rar": "application/x-rar-compressed",
|
|
"rpm": "application/x-redhat-package-manager",
|
|
"sea": "application/x-sea",
|
|
"swf": "application/x-shockwave-flash",
|
|
"sit": "application/x-stuffit",
|
|
"tcl": "application/x-tcl",
|
|
"tk": "application/x-tcl",
|
|
"der": "application/x-x509-ca-cert",
|
|
"pem": "application/x-x509-ca-cert",
|
|
"crt": "application/x-x509-ca-cert",
|
|
"xpi": "application/x-xpinstall",
|
|
"xhtml": "application/xhtml+xml",
|
|
"xspf": "application/xspf+xml",
|
|
"zip": "application/zip",
|
|
"bin": "application/octet-stream",
|
|
"exe": "application/octet-stream",
|
|
"dll": "application/octet-stream",
|
|
"deb": "application/octet-stream",
|
|
"dmg": "application/octet-stream",
|
|
"iso": "application/octet-stream",
|
|
"img": "application/octet-stream",
|
|
"msi": "application/octet-stream",
|
|
"msp": "application/octet-stream",
|
|
"msm": "application/octet-stream",
|
|
"mid": "audio/midi",
|
|
"midi": "audio/midi",
|
|
"kar": "audio/midi",
|
|
"mp3": "audio/mpeg",
|
|
"ogg": "audio/ogg",
|
|
"m4a": "audio/x-m4a",
|
|
"ra": "audio/x-realaudio",
|
|
"3gpp": "video/3gpp",
|
|
"3gp": "video/3gpp",
|
|
"ts": "video/mp2t",
|
|
"mp4": "video/mp4",
|
|
"mpeg": "video/mpeg",
|
|
"mpg": "video/mpeg",
|
|
"mov": "video/quicktime",
|
|
"webm": "video/webm",
|
|
"flv": "video/x-flv",
|
|
"m4v": "video/x-m4v",
|
|
"mng": "video/x-mng",
|
|
"asx": "video/x-ms-asf",
|
|
"asf": "video/x-ms-asf",
|
|
"wmv": "video/x-ms-wmv",
|
|
"avi": "video/x-msvideo",
|
|
}
|