mirror of
https://github.com/gofiber/fiber.git
synced 2025-02-12 02:41:05 +00:00
v1.8.34
This commit is contained in:
parent
5c619e872c
commit
b425a5b4bf
@ -1,11 +1,15 @@
|
||||
language: go
|
||||
sudo: false
|
||||
|
||||
os:
|
||||
- linux
|
||||
- windows
|
||||
- osx
|
||||
go:
|
||||
- 1.11.x
|
||||
- go: 1.11.x
|
||||
- go: 1.12.x
|
||||
- go: 1.13.x
|
||||
- go: 1.14.x
|
||||
env:
|
||||
- GO111MODULE=on
|
||||
install:
|
||||
|
70
app.go
70
app.go
@ -8,7 +8,6 @@ import (
|
||||
"bufio"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
@ -176,55 +175,55 @@ func (app *App) Use(args ...interface{}) *App {
|
||||
|
||||
// Connect : https://fiber.wiki/application#http-methods
|
||||
func (app *App) Connect(path string, handlers ...func(*Ctx)) *App {
|
||||
app.registerMethod(http.MethodConnect, path, handlers...)
|
||||
app.registerMethod(fasthttp.MethodConnect, path, handlers...)
|
||||
return app
|
||||
}
|
||||
|
||||
// Put : https://fiber.wiki/application#http-methods
|
||||
func (app *App) Put(path string, handlers ...func(*Ctx)) *App {
|
||||
app.registerMethod(http.MethodPut, path, handlers...)
|
||||
app.registerMethod(fasthttp.MethodPut, path, handlers...)
|
||||
return app
|
||||
}
|
||||
|
||||
// Post : https://fiber.wiki/application#http-methods
|
||||
func (app *App) Post(path string, handlers ...func(*Ctx)) *App {
|
||||
app.registerMethod(http.MethodPost, path, handlers...)
|
||||
app.registerMethod(fasthttp.MethodPost, path, handlers...)
|
||||
return app
|
||||
}
|
||||
|
||||
// Delete : https://fiber.wiki/application#http-methods
|
||||
func (app *App) Delete(path string, handlers ...func(*Ctx)) *App {
|
||||
app.registerMethod(http.MethodDelete, path, handlers...)
|
||||
app.registerMethod(fasthttp.MethodDelete, path, handlers...)
|
||||
return app
|
||||
}
|
||||
|
||||
// Head : https://fiber.wiki/application#http-methods
|
||||
func (app *App) Head(path string, handlers ...func(*Ctx)) *App {
|
||||
app.registerMethod(http.MethodHead, path, handlers...)
|
||||
app.registerMethod(fasthttp.MethodHead, path, handlers...)
|
||||
return app
|
||||
}
|
||||
|
||||
// Patch : https://fiber.wiki/application#http-methods
|
||||
func (app *App) Patch(path string, handlers ...func(*Ctx)) *App {
|
||||
app.registerMethod(http.MethodPatch, path, handlers...)
|
||||
app.registerMethod(fasthttp.MethodPatch, path, handlers...)
|
||||
return app
|
||||
}
|
||||
|
||||
// Options : https://fiber.wiki/application#http-methods
|
||||
func (app *App) Options(path string, handlers ...func(*Ctx)) *App {
|
||||
app.registerMethod(http.MethodOptions, path, handlers...)
|
||||
app.registerMethod(fasthttp.MethodOptions, path, handlers...)
|
||||
return app
|
||||
}
|
||||
|
||||
// Trace : https://fiber.wiki/application#http-methods
|
||||
func (app *App) Trace(path string, handlers ...func(*Ctx)) *App {
|
||||
app.registerMethod(http.MethodTrace, path, handlers...)
|
||||
app.registerMethod(fasthttp.MethodTrace, path, handlers...)
|
||||
return app
|
||||
}
|
||||
|
||||
// Get : https://fiber.wiki/application#http-methods
|
||||
func (app *App) Get(path string, handlers ...func(*Ctx)) *App {
|
||||
app.registerMethod(http.MethodGet, path, handlers...)
|
||||
app.registerMethod(fasthttp.MethodGet, path, handlers...)
|
||||
return app
|
||||
}
|
||||
|
||||
@ -240,21 +239,6 @@ func (app *App) All(path string, handlers ...func(*Ctx)) *App {
|
||||
return app
|
||||
}
|
||||
|
||||
// This function is deprecated since v1.8.2!
|
||||
// Please us github.com/gofiber/websocket
|
||||
func (app *App) WebSocket(path string, handle func(*Ctx)) *App {
|
||||
log.Println("Warning: app.WebSocket() is deprecated since v1.8.2, please use github.com/gofiber/websocket instead.")
|
||||
app.registerWebSocket(http.MethodGet, path, handle)
|
||||
return app
|
||||
}
|
||||
|
||||
// This function is deprecated since v1.8.2!
|
||||
// Please us github.com/gofiber/recover
|
||||
func (app *App) Recover(handler func(*Ctx)) {
|
||||
log.Println("Warning: app.Recover() is deprecated since v1.8.2, please use github.com/gofiber/recover instead.")
|
||||
app.recover = handler
|
||||
}
|
||||
|
||||
// Listen : https://fiber.wiki/application#listen
|
||||
func (app *App) Listen(address interface{}, tlsconfig ...*tls.Config) error {
|
||||
addr, ok := address.(string)
|
||||
@ -305,18 +289,17 @@ func (app *App) Shutdown() error {
|
||||
|
||||
// Test : https://fiber.wiki/application#test
|
||||
func (app *App) Test(request *http.Request) (*http.Response, error) {
|
||||
// Get raw http request
|
||||
reqRaw, err := httputil.DumpRequest(request, true)
|
||||
// Dump raw http request
|
||||
dump, err := httputil.DumpRequest(request, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Setup a fiber server struct
|
||||
// Setup server
|
||||
app.server = app.newServer()
|
||||
// Create fake connection
|
||||
conn := &testConn{}
|
||||
// Pass HTTP request to conn
|
||||
_, err = conn.r.Write(reqRaw)
|
||||
if err != nil {
|
||||
// Create conn
|
||||
conn := new(testConn)
|
||||
// Write raw http request
|
||||
if _, err = conn.r.Write(dump); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Serve conn to server
|
||||
@ -330,19 +313,12 @@ func (app *App) Test(request *http.Request) (*http.Response, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Throw timeout error after 200ms
|
||||
case <-time.After(200 * time.Millisecond):
|
||||
return nil, fmt.Errorf("timeout")
|
||||
return nil, fmt.Errorf("Timeout error")
|
||||
}
|
||||
// Get raw HTTP response
|
||||
respRaw, err := ioutil.ReadAll(&conn.w)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Create buffer
|
||||
reader := strings.NewReader(getString(respRaw))
|
||||
buffer := bufio.NewReader(reader)
|
||||
// Convert raw HTTP response to http.Response
|
||||
// Read response
|
||||
buffer := bufio.NewReader(&conn.w)
|
||||
// Convert raw http response to *http.Response
|
||||
resp, err := http.ReadResponse(buffer, request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -393,9 +369,9 @@ func (app *App) prefork(address string) (ln net.Listener, err error) {
|
||||
return ln, err
|
||||
}
|
||||
|
||||
type disableLogger struct{}
|
||||
type customLogger struct{}
|
||||
|
||||
func (dl *disableLogger) Printf(format string, args ...interface{}) {
|
||||
func (cl *customLogger) Printf(format string, args ...interface{}) {
|
||||
// fmt.Println(fmt.Sprintf(format, args...))
|
||||
}
|
||||
|
||||
@ -405,7 +381,7 @@ func (app *App) newServer() *fasthttp.Server {
|
||||
Name: app.Settings.ServerHeader,
|
||||
MaxRequestBodySize: app.Settings.BodyLimit,
|
||||
NoDefaultServerHeader: app.Settings.ServerHeader == "",
|
||||
Logger: &disableLogger{},
|
||||
Logger: &customLogger{},
|
||||
LogAllErrors: false,
|
||||
ErrorHandler: func(ctx *fasthttp.RequestCtx, err error) {
|
||||
if err.Error() == "body size exceeds the given limit" {
|
||||
|
547
consts.go
Normal file
547
consts.go
Normal file
@ -0,0 +1,547 @@
|
||||
// 🚀 Fiber is an Express inspired web framework written in Go with 💖
|
||||
// 📌 API Documentation: https://fiber.wiki
|
||||
// 📝 Github Repository: https://github.com/gofiber/fiber
|
||||
|
||||
package fiber
|
||||
|
||||
// HTTP status codes were copied from net/http.
|
||||
var statusMessages = map[int]string{
|
||||
100: "Continue",
|
||||
101: "Switching Protocols",
|
||||
102: "Processing",
|
||||
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",
|
||||
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 labstack/echo
|
||||
const (
|
||||
MIMETextXML = "text/xml"
|
||||
MIMETextHTML = "text/html"
|
||||
MIMETextPlain = "text/plain"
|
||||
|
||||
MIMEApplicationJSON = "application/json"
|
||||
MIMEApplicationJavaScript = "application/javascript"
|
||||
MIMEApplicationXML = "application/xml"
|
||||
MIMEApplicationForm = "application/x-www-form-urlencoded"
|
||||
|
||||
MIMEMultipartForm = "multipart/form-data"
|
||||
|
||||
MIMEOctetStream = "application/octet-stream"
|
||||
)
|
||||
|
||||
// MIME types were copied from nginx/mime.types.
|
||||
var extensionMIME = map[string]string{
|
||||
// without dot
|
||||
"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",
|
||||
|
||||
// with dot
|
||||
".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",
|
||||
}
|
||||
|
||||
// HTTP methods were copied from net/http.
|
||||
const (
|
||||
MethodGet = "GET" // RFC 7231, 4.3.1
|
||||
MethodHead = "HEAD" // RFC 7231, 4.3.2
|
||||
MethodPost = "POST" // RFC 7231, 4.3.3
|
||||
MethodPut = "PUT" // RFC 7231, 4.3.4
|
||||
MethodPatch = "PATCH" // RFC 5789
|
||||
MethodDelete = "DELETE" // RFC 7231, 4.3.5
|
||||
MethodConnect = "CONNECT" // RFC 7231, 4.3.6
|
||||
MethodOptions = "OPTIONS" // RFC 7231, 4.3.7
|
||||
MethodTrace = "TRACE" // RFC 7231, 4.3.8
|
||||
)
|
||||
|
||||
// HTTP Headers were copied from net/http.
|
||||
const (
|
||||
// Authentication
|
||||
HeaderAuthorization = "Authorization"
|
||||
HeaderProxyAuthenticate = "Proxy-Authenticate"
|
||||
HeaderProxyAuthorization = "Proxy-Authorization"
|
||||
HeaderWWWAuthenticate = "WWW-Authenticate"
|
||||
|
||||
// Caching
|
||||
HeaderAge = "Age"
|
||||
HeaderCacheControl = "Cache-Control"
|
||||
HeaderClearSiteData = "Clear-Site-Data"
|
||||
HeaderExpires = "Expires"
|
||||
HeaderPragma = "Pragma"
|
||||
HeaderWarning = "Warning"
|
||||
|
||||
// Client hints
|
||||
HeaderAcceptCH = "Accept-CH"
|
||||
HeaderAcceptCHLifetime = "Accept-CH-Lifetime"
|
||||
HeaderContentDPR = "Content-DPR"
|
||||
HeaderDPR = "DPR"
|
||||
HeaderEarlyData = "Early-Data"
|
||||
HeaderSaveData = "Save-Data"
|
||||
HeaderViewportWidth = "Viewport-Width"
|
||||
HeaderWidth = "Width"
|
||||
|
||||
// Conditionals
|
||||
HeaderETag = "ETag"
|
||||
HeaderIfMatch = "If-Match"
|
||||
HeaderIfModifiedSince = "If-Modified-Since"
|
||||
HeaderIfNoneMatch = "If-None-Match"
|
||||
HeaderIfUnmodifiedSince = "If-Unmodified-Since"
|
||||
HeaderLastModified = "Last-Modified"
|
||||
HeaderVary = "Vary"
|
||||
|
||||
// Connection management
|
||||
HeaderConnection = "Connection"
|
||||
HeaderKeepAlive = "Keep-Alive"
|
||||
|
||||
// Content negotiation
|
||||
HeaderAccept = "Accept"
|
||||
HeaderAcceptCharset = "Accept-Charset"
|
||||
HeaderAcceptEncoding = "Accept-Encoding"
|
||||
HeaderAcceptLanguage = "Accept-Language"
|
||||
|
||||
// Controls
|
||||
HeaderCookie = "Cookie"
|
||||
HeaderExpect = "Expect"
|
||||
HeaderMaxForwards = "Max-Forwards"
|
||||
HeaderSetCookie = "Set-Cookie"
|
||||
|
||||
// CORS
|
||||
HeaderAccessControlAllowCredentials = "Access-Control-Allow-Credentials"
|
||||
HeaderAccessControlAllowHeaders = "Access-Control-Allow-Headers"
|
||||
HeaderAccessControlAllowMethods = "Access-Control-Allow-Methods"
|
||||
HeaderAccessControlAllowOrigin = "Access-Control-Allow-Origin"
|
||||
HeaderAccessControlExposeHeaders = "Access-Control-Expose-Headers"
|
||||
HeaderAccessControlMaxAge = "Access-Control-Max-Age"
|
||||
HeaderAccessControlRequestHeaders = "Access-Control-Request-Headers"
|
||||
HeaderAccessControlRequestMethod = "Access-Control-Request-Method"
|
||||
HeaderOrigin = "Origin"
|
||||
HeaderTimingAllowOrigin = "Timing-Allow-Origin"
|
||||
HeaderXPermittedCrossDomainPolicies = "X-Permitted-Cross-Domain-Policies"
|
||||
|
||||
// Do Not Track
|
||||
HeaderDNT = "DNT"
|
||||
HeaderTk = "Tk"
|
||||
|
||||
// Downloads
|
||||
HeaderContentDisposition = "Content-Disposition"
|
||||
|
||||
// Message body information
|
||||
HeaderContentEncoding = "Content-Encoding"
|
||||
HeaderContentLanguage = "Content-Language"
|
||||
HeaderContentLength = "Content-Length"
|
||||
HeaderContentLocation = "Content-Location"
|
||||
HeaderContentType = "Content-Type"
|
||||
|
||||
// Proxies
|
||||
HeaderForwarded = "Forwarded"
|
||||
HeaderVia = "Via"
|
||||
HeaderXForwardedFor = "X-Forwarded-For"
|
||||
HeaderXForwardedHost = "X-Forwarded-Host"
|
||||
HeaderXForwardedProto = "X-Forwarded-Proto"
|
||||
|
||||
// Redirects
|
||||
HeaderLocation = "Location"
|
||||
|
||||
// Request context
|
||||
HeaderFrom = "From"
|
||||
HeaderHost = "Host"
|
||||
HeaderReferer = "Referer"
|
||||
HeaderReferrerPolicy = "Referrer-Policy"
|
||||
HeaderUserAgent = "User-Agent"
|
||||
|
||||
// Response context
|
||||
HeaderAllow = "Allow"
|
||||
HeaderServer = "Server"
|
||||
|
||||
// Range requests
|
||||
HeaderAcceptRanges = "Accept-Ranges"
|
||||
HeaderContentRange = "Content-Range"
|
||||
HeaderIfRange = "If-Range"
|
||||
HeaderRange = "Range"
|
||||
|
||||
// Security
|
||||
HeaderContentSecurityPolicy = "Content-Security-Policy"
|
||||
HeaderContentSecurityPolicyReportOnly = "Content-Security-Policy-Report-Only"
|
||||
HeaderCrossOriginResourcePolicy = "Cross-Origin-Resource-Policy"
|
||||
HeaderExpectCT = "Expect-CT"
|
||||
HeaderFeaturePolicy = "Feature-Policy"
|
||||
HeaderPublicKeyPins = "Public-Key-Pins"
|
||||
HeaderPublicKeyPinsReportOnly = "Public-Key-Pins-Report-Only"
|
||||
HeaderStrictTransportSecurity = "Strict-Transport-Security"
|
||||
HeaderUpgradeInsecureRequests = "Upgrade-Insecure-Requests"
|
||||
HeaderXContentTypeOptions = "X-Content-Type-Options"
|
||||
HeaderXDownloadOptions = "X-Download-Options"
|
||||
HeaderXFrameOptions = "X-Frame-Options"
|
||||
HeaderXPoweredBy = "X-Powered-By"
|
||||
HeaderXXSSProtection = "X-XSS-Protection"
|
||||
|
||||
// Server-sent event
|
||||
HeaderLastEventID = "Last-Event-ID"
|
||||
HeaderNEL = "NEL"
|
||||
HeaderPingFrom = "Ping-From"
|
||||
HeaderPingTo = "Ping-To"
|
||||
HeaderReportTo = "Report-To"
|
||||
|
||||
// Transfer coding
|
||||
HeaderTE = "TE"
|
||||
HeaderTrailer = "Trailer"
|
||||
HeaderTransferEncoding = "Transfer-Encoding"
|
||||
|
||||
// WebSockets
|
||||
HeaderSecWebSocketAccept = "Sec-WebSocket-Accept"
|
||||
HeaderSecWebSocketExtensions = "Sec-WebSocket-Extensions"
|
||||
HeaderSecWebSocketKey = "Sec-WebSocket-Key"
|
||||
HeaderSecWebSocketProtocol = "Sec-WebSocket-Protocol"
|
||||
HeaderSecWebSocketVersion = "Sec-WebSocket-Version"
|
||||
|
||||
// Other
|
||||
HeaderAcceptPatch = "Accept-Patch"
|
||||
HeaderAcceptPushPolicy = "Accept-Push-Policy"
|
||||
HeaderAcceptSignature = "Accept-Signature"
|
||||
HeaderAltSvc = "Alt-Svc"
|
||||
HeaderDate = "Date"
|
||||
HeaderIndex = "Index"
|
||||
HeaderLargeAllocation = "Large-Allocation"
|
||||
HeaderLink = "Link"
|
||||
HeaderPushPolicy = "Push-Policy"
|
||||
HeaderRetryAfter = "Retry-After"
|
||||
HeaderServerTiming = "Server-Timing"
|
||||
HeaderSignature = "Signature"
|
||||
HeaderSignedHeaders = "Signed-Headers"
|
||||
HeaderSourceMap = "SourceMap"
|
||||
HeaderUpgrade = "Upgrade"
|
||||
HeaderXDNSPrefetchControl = "X-DNS-Prefetch-Control"
|
||||
HeaderXPingback = "X-Pingback"
|
||||
HeaderXRequestID = "X-Request-ID"
|
||||
HeaderXRequestedWith = "X-Requested-With"
|
||||
HeaderXRobotsTag = "X-Robots-Tag"
|
||||
HeaderXUACompatible = "X-UA-Compatible"
|
||||
)
|
||||
|
||||
// HTTP status codes were copied from net/http.
|
||||
const (
|
||||
StatusContinue = 100 // RFC 7231, 6.2.1
|
||||
StatusSwitchingProtocols = 101 // RFC 7231, 6.2.2
|
||||
StatusProcessing = 102 // RFC 2518, 10.1
|
||||
|
||||
StatusOK = 200 // RFC 7231, 6.3.1
|
||||
StatusCreated = 201 // RFC 7231, 6.3.2
|
||||
StatusAccepted = 202 // RFC 7231, 6.3.3
|
||||
StatusNonAuthoritativeInfo = 203 // RFC 7231, 6.3.4
|
||||
StatusNoContent = 204 // RFC 7231, 6.3.5
|
||||
StatusResetContent = 205 // RFC 7231, 6.3.6
|
||||
StatusPartialContent = 206 // RFC 7233, 4.1
|
||||
StatusMultiStatus = 207 // RFC 4918, 11.1
|
||||
StatusAlreadyReported = 208 // RFC 5842, 7.1
|
||||
StatusIMUsed = 226 // RFC 3229, 10.4.1
|
||||
|
||||
StatusMultipleChoices = 300 // RFC 7231, 6.4.1
|
||||
StatusMovedPermanently = 301 // RFC 7231, 6.4.2
|
||||
StatusFound = 302 // RFC 7231, 6.4.3
|
||||
StatusSeeOther = 303 // RFC 7231, 6.4.4
|
||||
StatusNotModified = 304 // RFC 7232, 4.1
|
||||
StatusUseProxy = 305 // RFC 7231, 6.4.5
|
||||
|
||||
StatusTemporaryRedirect = 307 // RFC 7231, 6.4.7
|
||||
StatusPermanentRedirect = 308 // RFC 7538, 3
|
||||
|
||||
StatusBadRequest = 400 // RFC 7231, 6.5.1
|
||||
StatusUnauthorized = 401 // RFC 7235, 3.1
|
||||
StatusPaymentRequired = 402 // RFC 7231, 6.5.2
|
||||
StatusForbidden = 403 // RFC 7231, 6.5.3
|
||||
StatusNotFound = 404 // RFC 7231, 6.5.4
|
||||
StatusMethodNotAllowed = 405 // RFC 7231, 6.5.5
|
||||
StatusNotAcceptable = 406 // RFC 7231, 6.5.6
|
||||
StatusProxyAuthRequired = 407 // RFC 7235, 3.2
|
||||
StatusRequestTimeout = 408 // RFC 7231, 6.5.7
|
||||
StatusConflict = 409 // RFC 7231, 6.5.8
|
||||
StatusGone = 410 // RFC 7231, 6.5.9
|
||||
StatusLengthRequired = 411 // RFC 7231, 6.5.10
|
||||
StatusPreconditionFailed = 412 // RFC 7232, 4.2
|
||||
StatusRequestEntityTooLarge = 413 // RFC 7231, 6.5.11
|
||||
StatusRequestURITooLong = 414 // RFC 7231, 6.5.12
|
||||
StatusUnsupportedMediaType = 415 // RFC 7231, 6.5.13
|
||||
StatusRequestedRangeNotSatisfiable = 416 // RFC 7233, 4.4
|
||||
StatusExpectationFailed = 417 // RFC 7231, 6.5.14
|
||||
StatusTeapot = 418 // RFC 7168, 2.3.3
|
||||
StatusUnprocessableEntity = 422 // RFC 4918, 11.2
|
||||
StatusLocked = 423 // RFC 4918, 11.3
|
||||
StatusFailedDependency = 424 // RFC 4918, 11.4
|
||||
StatusUpgradeRequired = 426 // RFC 7231, 6.5.15
|
||||
StatusPreconditionRequired = 428 // RFC 6585, 3
|
||||
StatusTooManyRequests = 429 // RFC 6585, 4
|
||||
StatusRequestHeaderFieldsTooLarge = 431 // RFC 6585, 5
|
||||
StatusUnavailableForLegalReasons = 451 // RFC 7725, 3
|
||||
|
||||
StatusInternalServerError = 500 // RFC 7231, 6.6.1
|
||||
StatusNotImplemented = 501 // RFC 7231, 6.6.2
|
||||
StatusBadGateway = 502 // RFC 7231, 6.6.3
|
||||
StatusServiceUnavailable = 503 // RFC 7231, 6.6.4
|
||||
StatusGatewayTimeout = 504 // RFC 7231, 6.6.5
|
||||
StatusHTTPVersionNotSupported = 505 // RFC 7231, 6.6.6
|
||||
StatusVariantAlsoNegotiates = 506 // RFC 2295, 8.1
|
||||
StatusInsufficientStorage = 507 // RFC 4918, 11.5
|
||||
StatusLoopDetected = 508 // RFC 5842, 7.2
|
||||
StatusNotExtended = 510 // RFC 2774, 7
|
||||
StatusNetworkAuthenticationRequired = 511 // RFC 6585, 6
|
||||
)
|
31
context.go
31
context.go
@ -57,6 +57,7 @@ type Cookie struct {
|
||||
Expires time.Time
|
||||
Secure bool
|
||||
HTTPOnly bool
|
||||
SameSite string
|
||||
}
|
||||
|
||||
// Ctx pool
|
||||
@ -125,7 +126,7 @@ func (ctx *Ctx) Accepts(offers ...string) (offer string) {
|
||||
|
||||
specs := strings.Split(h, ",")
|
||||
for _, value := range offers {
|
||||
mimetype := getType(value)
|
||||
mimetype := getMIME(value)
|
||||
// if mimetype != "" {
|
||||
// mimetype = strings.Split(mimetype, ";")[0]
|
||||
// } else {
|
||||
@ -343,16 +344,6 @@ func (ctx *Ctx) ClearCookie(key ...string) {
|
||||
})
|
||||
}
|
||||
|
||||
// This function is deprecated since v1.8.2!
|
||||
// Please us github.com/gofiber/compression
|
||||
func (ctx *Ctx) Compress(enable ...bool) {
|
||||
log.Println("Warning: c.Compress() is deprecated since v1.8.2, please use github.com/gofiber/compression instead.")
|
||||
ctx.compress = true
|
||||
if len(enable) > 0 {
|
||||
ctx.compress = enable[0]
|
||||
}
|
||||
}
|
||||
|
||||
// Set cookie by passing a cookie struct
|
||||
//
|
||||
// https://fiber.wiki/context#cookie
|
||||
@ -364,7 +355,23 @@ func (ctx *Ctx) Cookie(cookie *Cookie) {
|
||||
fcookie.SetDomain(cookie.Domain)
|
||||
fcookie.SetExpire(cookie.Expires)
|
||||
fcookie.SetSecure(cookie.Secure)
|
||||
if cookie.Secure {
|
||||
// Secure must be paired with SameSite=None
|
||||
fcookie.SetSameSite(fasthttp.CookieSameSiteNoneMode)
|
||||
}
|
||||
fcookie.SetHTTPOnly(cookie.HTTPOnly)
|
||||
switch strings.ToLower(cookie.SameSite) {
|
||||
case "lax":
|
||||
fcookie.SetSameSite(fasthttp.CookieSameSiteLaxMode)
|
||||
case "strict":
|
||||
fcookie.SetSameSite(fasthttp.CookieSameSiteStrictMode)
|
||||
case "none":
|
||||
fcookie.SetSameSite(fasthttp.CookieSameSiteNoneMode)
|
||||
// Secure must be paired with SameSite=None
|
||||
fcookie.SetSecure(true)
|
||||
default:
|
||||
fcookie.SetSameSite(fasthttp.CookieSameSiteDisabled)
|
||||
}
|
||||
ctx.Fasthttp.Response.Header.SetCookie(fcookie)
|
||||
}
|
||||
|
||||
@ -912,7 +919,7 @@ func (ctx *Ctx) Status(status int) *Ctx {
|
||||
//
|
||||
// https://fiber.wiki/context#type
|
||||
func (ctx *Ctx) Type(ext string) *Ctx {
|
||||
ctx.Fasthttp.Response.Header.SetContentType(getType(ext))
|
||||
ctx.Fasthttp.Response.Header.SetContentType(getMIME(ext))
|
||||
return ctx
|
||||
}
|
||||
|
||||
|
115
deprecated.go
Normal file
115
deprecated.go
Normal file
@ -0,0 +1,115 @@
|
||||
// 🚀 Fiber is an Express inspired web framework written in Go with 💖
|
||||
// 📌 API Documentation: https://fiber.wiki
|
||||
// 📝 Github Repository: https://github.com/gofiber/fiber
|
||||
|
||||
package fiber
|
||||
|
||||
import (
|
||||
"log"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
websocket "github.com/fasthttp/websocket"
|
||||
fasthttp "github.com/valyala/fasthttp"
|
||||
)
|
||||
|
||||
// These variables are deprecated since v1.8.2!
|
||||
var compressResponse = fasthttp.CompressHandlerLevel(func(c *fasthttp.RequestCtx) {}, fasthttp.CompressDefaultCompression)
|
||||
var websocketUpgrader = websocket.FastHTTPUpgrader{
|
||||
ReadBufferSize: 1024,
|
||||
WriteBufferSize: 1024,
|
||||
CheckOrigin: func(fctx *fasthttp.RequestCtx) bool {
|
||||
return true
|
||||
},
|
||||
}
|
||||
|
||||
// This function is deprecated since v1.8.2!
|
||||
// Please us github.com/gofiber/compression
|
||||
func (ctx *Ctx) Compress(enable ...bool) {
|
||||
log.Println("Warning: c.Compress() is deprecated since v1.8.2, please use github.com/gofiber/compression instead.")
|
||||
ctx.compress = true
|
||||
if len(enable) > 0 {
|
||||
ctx.compress = enable[0]
|
||||
}
|
||||
}
|
||||
|
||||
// This function is deprecated since v1.8.2!
|
||||
// Please us github.com/gofiber/websocket
|
||||
func (app *App) WebSocket(path string, handle func(*Ctx)) *App {
|
||||
log.Println("Warning: app.WebSocket() is deprecated since v1.8.2, please use github.com/gofiber/websocket instead.")
|
||||
app.registerWebSocket(fasthttp.MethodGet, path, handle)
|
||||
return app
|
||||
}
|
||||
|
||||
// This function is deprecated since v1.8.2!
|
||||
// Please us github.com/gofiber/websocket
|
||||
func (grp *Group) WebSocket(path string, handle func(*Ctx)) *Group {
|
||||
log.Println("Warning: app.WebSocket() is deprecated since v1.8.2, please use github.com/gofiber/websocket instead.")
|
||||
grp.app.registerWebSocket(fasthttp.MethodGet, groupPaths(grp.prefix, path), handle)
|
||||
return grp
|
||||
}
|
||||
|
||||
// This function is deprecated since v1.8.2!
|
||||
// Please us github.com/gofiber/recover
|
||||
func (app *App) Recover(handler func(*Ctx)) {
|
||||
log.Println("Warning: app.Recover() is deprecated since v1.8.2, please use github.com/gofiber/recover instead.")
|
||||
app.recover = handler
|
||||
}
|
||||
|
||||
// This function is deprecated since v1.8.2!
|
||||
// Please us github.com/gofiber/recover
|
||||
func (grp *Group) Recover(handler func(*Ctx)) {
|
||||
log.Println("Warning: Recover() is deprecated since v1.8.2, please use github.com/gofiber/recover instead.")
|
||||
grp.app.recover = handler
|
||||
}
|
||||
|
||||
func (app *App) registerWebSocket(method, path string, handle func(*Ctx)) {
|
||||
// Cannot have an empty path
|
||||
if path == "" {
|
||||
path = "/"
|
||||
}
|
||||
// Path always start with a '/' or '*'
|
||||
if path[0] != '/' && path[0] != '*' {
|
||||
path = "/" + path
|
||||
}
|
||||
// Store original path to strip case sensitive params
|
||||
original := path
|
||||
// Case sensitive routing, all to lowercase
|
||||
if !app.Settings.CaseSensitive {
|
||||
path = strings.ToLower(path)
|
||||
}
|
||||
// Strict routing, remove last `/`
|
||||
if !app.Settings.StrictRouting && len(path) > 1 {
|
||||
path = strings.TrimRight(path, "/")
|
||||
}
|
||||
|
||||
var isWebSocket = true
|
||||
|
||||
var isStar = path == "*" || path == "/*"
|
||||
var isSlash = path == "/"
|
||||
var isRegex = false
|
||||
// Route properties
|
||||
var Params = getParams(original)
|
||||
var Regexp *regexp.Regexp
|
||||
// Params requires regex pattern
|
||||
if len(Params) > 0 {
|
||||
regex, err := getRegex(path)
|
||||
if err != nil {
|
||||
log.Fatal("Router: Invalid path pattern: " + path)
|
||||
}
|
||||
isRegex = true
|
||||
Regexp = regex
|
||||
}
|
||||
app.routes = append(app.routes, &Route{
|
||||
isWebSocket: isWebSocket,
|
||||
isStar: isStar,
|
||||
isSlash: isSlash,
|
||||
isRegex: isRegex,
|
||||
|
||||
Method: method,
|
||||
Path: path,
|
||||
Params: Params,
|
||||
Regexp: Regexp,
|
||||
HandleCtx: handle,
|
||||
})
|
||||
}
|
55
group.go
55
group.go
@ -6,8 +6,8 @@ package fiber
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"reflect"
|
||||
|
||||
fasthttp "github.com/valyala/fasthttp"
|
||||
)
|
||||
|
||||
// Group ...
|
||||
@ -53,74 +53,64 @@ func (grp *Group) Use(args ...interface{}) *Group {
|
||||
case func(*Ctx):
|
||||
handlers = append(handlers, arg)
|
||||
default:
|
||||
log.Fatalf("Invalid handler: %v", reflect.TypeOf(arg))
|
||||
log.Fatalf("Invalid Use() arguments, must be (prefix, handler) or (handler)")
|
||||
}
|
||||
}
|
||||
path = groupPaths(grp.prefix, path)
|
||||
grp.app.registerMethod("USE", path, handlers...)
|
||||
grp.app.registerMethod("USE", groupPaths(grp.prefix, path), handlers...)
|
||||
return grp
|
||||
}
|
||||
|
||||
// Connect : https://fiber.wiki/application#http-methods
|
||||
func (grp *Group) Connect(path string, handlers ...func(*Ctx)) *Group {
|
||||
path = groupPaths(grp.prefix, path)
|
||||
grp.app.registerMethod(http.MethodConnect, path, handlers...)
|
||||
grp.app.registerMethod(fasthttp.MethodConnect, groupPaths(grp.prefix, path), handlers...)
|
||||
return grp
|
||||
}
|
||||
|
||||
// Put : https://fiber.wiki/application#http-methods
|
||||
func (grp *Group) Put(path string, handlers ...func(*Ctx)) *Group {
|
||||
path = groupPaths(grp.prefix, path)
|
||||
grp.app.registerMethod(http.MethodPut, path, handlers...)
|
||||
grp.app.registerMethod(fasthttp.MethodPut, groupPaths(grp.prefix, path), handlers...)
|
||||
return grp
|
||||
}
|
||||
|
||||
// Post : https://fiber.wiki/application#http-methods
|
||||
func (grp *Group) Post(path string, handlers ...func(*Ctx)) *Group {
|
||||
path = groupPaths(grp.prefix, path)
|
||||
grp.app.registerMethod(http.MethodPost, path, handlers...)
|
||||
grp.app.registerMethod(fasthttp.MethodPost, groupPaths(grp.prefix, path), handlers...)
|
||||
return grp
|
||||
}
|
||||
|
||||
// Delete : https://fiber.wiki/application#http-methods
|
||||
func (grp *Group) Delete(path string, handlers ...func(*Ctx)) *Group {
|
||||
path = groupPaths(grp.prefix, path)
|
||||
grp.app.registerMethod(http.MethodDelete, path, handlers...)
|
||||
grp.app.registerMethod(fasthttp.MethodDelete, groupPaths(grp.prefix, path), handlers...)
|
||||
return grp
|
||||
}
|
||||
|
||||
// Head : https://fiber.wiki/application#http-methods
|
||||
func (grp *Group) Head(path string, handlers ...func(*Ctx)) *Group {
|
||||
path = groupPaths(grp.prefix, path)
|
||||
grp.app.registerMethod(http.MethodHead, path, handlers...)
|
||||
grp.app.registerMethod(fasthttp.MethodHead, groupPaths(grp.prefix, path), handlers...)
|
||||
return grp
|
||||
}
|
||||
|
||||
// Patch : https://fiber.wiki/application#http-methods
|
||||
func (grp *Group) Patch(path string, handlers ...func(*Ctx)) *Group {
|
||||
path = groupPaths(grp.prefix, path)
|
||||
grp.app.registerMethod(http.MethodPatch, path, handlers...)
|
||||
grp.app.registerMethod(fasthttp.MethodPatch, groupPaths(grp.prefix, path), handlers...)
|
||||
return grp
|
||||
}
|
||||
|
||||
// Options : https://fiber.wiki/application#http-methods
|
||||
func (grp *Group) Options(path string, handlers ...func(*Ctx)) *Group {
|
||||
path = groupPaths(grp.prefix, path)
|
||||
grp.app.registerMethod(http.MethodOptions, path, handlers...)
|
||||
grp.app.registerMethod(fasthttp.MethodOptions, groupPaths(grp.prefix, path), handlers...)
|
||||
return grp
|
||||
}
|
||||
|
||||
// Trace : https://fiber.wiki/application#http-methods
|
||||
func (grp *Group) Trace(path string, handlers ...func(*Ctx)) *Group {
|
||||
path = groupPaths(grp.prefix, path)
|
||||
grp.app.registerMethod(http.MethodTrace, path, handlers...)
|
||||
grp.app.registerMethod(fasthttp.MethodTrace, groupPaths(grp.prefix, path), handlers...)
|
||||
return grp
|
||||
}
|
||||
|
||||
// Get : https://fiber.wiki/application#http-methods
|
||||
func (grp *Group) Get(path string, handlers ...func(*Ctx)) *Group {
|
||||
path = groupPaths(grp.prefix, path)
|
||||
grp.app.registerMethod(http.MethodGet, path, handlers...)
|
||||
grp.app.registerMethod(fasthttp.MethodGet, groupPaths(grp.prefix, path), handlers...)
|
||||
return grp
|
||||
}
|
||||
|
||||
@ -132,23 +122,6 @@ func (grp *Group) Get(path string, handlers ...func(*Ctx)) *Group {
|
||||
//
|
||||
// https://fiber.wiki/application#http-methods
|
||||
func (grp *Group) All(path string, handlers ...func(*Ctx)) *Group {
|
||||
path = groupPaths(grp.prefix, path)
|
||||
grp.app.registerMethod("ALL", path, handlers...)
|
||||
grp.app.registerMethod("ALL", groupPaths(grp.prefix, path), handlers...)
|
||||
return grp
|
||||
}
|
||||
|
||||
// This function is deprecated since v1.8.2!
|
||||
// Please us github.com/gofiber/websocket
|
||||
func (grp *Group) WebSocket(path string, handle func(*Ctx)) *Group {
|
||||
log.Println("Warning: app.WebSocket() is deprecated since v1.8.2, please use github.com/gofiber/websocket instead.")
|
||||
path = groupPaths(grp.prefix, path)
|
||||
grp.app.registerWebSocket(http.MethodGet, path, handle)
|
||||
return grp
|
||||
}
|
||||
|
||||
// This function is deprecated since v1.8.2!
|
||||
// Please us github.com/gofiber/recover
|
||||
func (grp *Group) Recover(handler func(*Ctx)) {
|
||||
log.Println("Warning: Recover() is deprecated since v1.8.2, please use github.com/gofiber/recover instead.")
|
||||
grp.app.recover = handler
|
||||
}
|
||||
|
51
router.go
51
router.go
@ -206,57 +206,6 @@ func (app *App) registerMethod(method, path string, handlers ...func(*Ctx)) {
|
||||
}
|
||||
}
|
||||
|
||||
func (app *App) registerWebSocket(method, path string, handle func(*Ctx)) {
|
||||
// Cannot have an empty path
|
||||
if path == "" {
|
||||
path = "/"
|
||||
}
|
||||
// Path always start with a '/' or '*'
|
||||
if path[0] != '/' && path[0] != '*' {
|
||||
path = "/" + path
|
||||
}
|
||||
// Store original path to strip case sensitive params
|
||||
original := path
|
||||
// Case sensitive routing, all to lowercase
|
||||
if !app.Settings.CaseSensitive {
|
||||
path = strings.ToLower(path)
|
||||
}
|
||||
// Strict routing, remove last `/`
|
||||
if !app.Settings.StrictRouting && len(path) > 1 {
|
||||
path = strings.TrimRight(path, "/")
|
||||
}
|
||||
|
||||
var isWebSocket = true
|
||||
|
||||
var isStar = path == "*" || path == "/*"
|
||||
var isSlash = path == "/"
|
||||
var isRegex = false
|
||||
// Route properties
|
||||
var Params = getParams(original)
|
||||
var Regexp *regexp.Regexp
|
||||
// Params requires regex pattern
|
||||
if len(Params) > 0 {
|
||||
regex, err := getRegex(path)
|
||||
if err != nil {
|
||||
log.Fatal("Router: Invalid path pattern: " + path)
|
||||
}
|
||||
isRegex = true
|
||||
Regexp = regex
|
||||
}
|
||||
app.routes = append(app.routes, &Route{
|
||||
isWebSocket: isWebSocket,
|
||||
isStar: isStar,
|
||||
isSlash: isSlash,
|
||||
isRegex: isRegex,
|
||||
|
||||
Method: method,
|
||||
Path: path,
|
||||
Params: Params,
|
||||
Regexp: Regexp,
|
||||
HandleCtx: handle,
|
||||
})
|
||||
}
|
||||
|
||||
func (app *App) registerStatic(prefix, root string, config ...Static) {
|
||||
// Cannot have an empty prefix
|
||||
if prefix == "" {
|
||||
|
448
utils.go
448
utils.go
@ -15,20 +15,10 @@ import (
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
websocket "github.com/fasthttp/websocket"
|
||||
schema "github.com/gorilla/schema"
|
||||
fasthttp "github.com/valyala/fasthttp"
|
||||
)
|
||||
|
||||
var schemaDecoder = schema.NewDecoder()
|
||||
var compressResponse = fasthttp.CompressHandlerLevel(func(c *fasthttp.RequestCtx) {}, fasthttp.CompressDefaultCompression)
|
||||
var websocketUpgrader = websocket.FastHTTPUpgrader{
|
||||
ReadBufferSize: 1024,
|
||||
WriteBufferSize: 1024,
|
||||
CheckOrigin: func(fctx *fasthttp.RequestCtx) bool {
|
||||
return true
|
||||
},
|
||||
}
|
||||
|
||||
func groupPaths(prefix, path string) string {
|
||||
if path == "/" {
|
||||
@ -39,15 +29,6 @@ func groupPaths(prefix, path string) string {
|
||||
return path
|
||||
}
|
||||
|
||||
// BenchmarkDefault 322504144 18.6 ns/op // string == string
|
||||
// BenchmarkisEqual 353663168 17.0 ns/op // isEqual(string, string)
|
||||
// func isEqual(a, b string) bool {
|
||||
// if len(a) == len(b) {
|
||||
// return a == b
|
||||
// }
|
||||
// return false
|
||||
// }
|
||||
|
||||
func getParams(path string) (params []string) {
|
||||
if len(path) < 1 {
|
||||
return
|
||||
@ -107,15 +88,11 @@ func getFiles(root string) (files []string, dir bool, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func getType(ext string) (mime string) {
|
||||
if ext == "" {
|
||||
func getMIME(extension string) (mime string) {
|
||||
if extension == "" {
|
||||
return mime
|
||||
}
|
||||
if ext[0] == '.' {
|
||||
mime = extensionMIME[ext[1:]]
|
||||
} else {
|
||||
mime = extensionMIME[ext]
|
||||
}
|
||||
mime = extensionMIME[extension]
|
||||
if mime == "" {
|
||||
return MIMEOctetStream
|
||||
}
|
||||
@ -156,422 +133,3 @@ func (c *testConn) Close() error { return nil }
|
||||
func (c *testConn) SetDeadline(t time.Time) error { return nil }
|
||||
func (c *testConn) SetReadDeadline(t time.Time) error { return nil }
|
||||
func (c *testConn) SetWriteDeadline(t time.Time) error { return nil }
|
||||
|
||||
// MIME types
|
||||
const (
|
||||
MIMEApplicationJSON = "application/json"
|
||||
MIMEApplicationJavaScript = "application/javascript"
|
||||
MIMEApplicationXML = "application/xml"
|
||||
MIMETextXML = "text/xml"
|
||||
MIMEApplicationForm = "application/x-www-form-urlencoded"
|
||||
MIMEApplicationProtobuf = "application/protobuf"
|
||||
MIMEApplicationMsgpack = "application/msgpack"
|
||||
MIMETextHTML = "text/html"
|
||||
MIMETextPlain = "text/plain"
|
||||
MIMEMultipartForm = "multipart/form-data"
|
||||
MIMEOctetStream = "application/octet-stream"
|
||||
)
|
||||
|
||||
// HTTP status codes with messages
|
||||
var statusMessages = map[int]string{
|
||||
100: "Continue",
|
||||
101: "Switching Protocols",
|
||||
102: "Processing",
|
||||
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",
|
||||
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",
|
||||
}
|
||||
|
||||
// File extensions MIME types
|
||||
var extensionMIME = 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",
|
||||
}
|
||||
|
||||
// HTTP Headers
|
||||
const (
|
||||
// Authentication
|
||||
HeaderAuthorization = "Authorization"
|
||||
HeaderProxyAuthenticate = "Proxy-Authenticate"
|
||||
HeaderProxyAuthorization = "Proxy-Authorization"
|
||||
HeaderWWWAuthenticate = "WWW-Authenticate"
|
||||
|
||||
// Caching
|
||||
HeaderAge = "Age"
|
||||
HeaderCacheControl = "Cache-Control"
|
||||
HeaderClearSiteData = "Clear-Site-Data"
|
||||
HeaderExpires = "Expires"
|
||||
HeaderPragma = "Pragma"
|
||||
HeaderWarning = "Warning"
|
||||
|
||||
// Client hints
|
||||
HeaderAcceptCH = "Accept-CH"
|
||||
HeaderAcceptCHLifetime = "Accept-CH-Lifetime"
|
||||
HeaderContentDPR = "Content-DPR"
|
||||
HeaderDPR = "DPR"
|
||||
HeaderEarlyData = "Early-Data"
|
||||
HeaderSaveData = "Save-Data"
|
||||
HeaderViewportWidth = "Viewport-Width"
|
||||
HeaderWidth = "Width"
|
||||
|
||||
// Conditionals
|
||||
HeaderETag = "ETag"
|
||||
HeaderIfMatch = "If-Match"
|
||||
HeaderIfModifiedSince = "If-Modified-Since"
|
||||
HeaderIfNoneMatch = "If-None-Match"
|
||||
HeaderIfUnmodifiedSince = "If-Unmodified-Since"
|
||||
HeaderLastModified = "Last-Modified"
|
||||
HeaderVary = "Vary"
|
||||
|
||||
// Connection management
|
||||
HeaderConnection = "Connection"
|
||||
HeaderKeepAlive = "Keep-Alive"
|
||||
|
||||
// Content negotiation
|
||||
HeaderAccept = "Accept"
|
||||
HeaderAcceptCharset = "Accept-Charset"
|
||||
HeaderAcceptEncoding = "Accept-Encoding"
|
||||
HeaderAcceptLanguage = "Accept-Language"
|
||||
|
||||
// Controls
|
||||
HeaderCookie = "Cookie"
|
||||
HeaderExpect = "Expect"
|
||||
HeaderMaxForwards = "Max-Forwards"
|
||||
HeaderSetCookie = "Set-Cookie"
|
||||
|
||||
// CORS
|
||||
HeaderAccessControlAllowCredentials = "Access-Control-Allow-Credentials"
|
||||
HeaderAccessControlAllowHeaders = "Access-Control-Allow-Headers"
|
||||
HeaderAccessControlAllowMethods = "Access-Control-Allow-Methods"
|
||||
HeaderAccessControlAllowOrigin = "Access-Control-Allow-Origin"
|
||||
HeaderAccessControlExposeHeaders = "Access-Control-Expose-Headers"
|
||||
HeaderAccessControlMaxAge = "Access-Control-Max-Age"
|
||||
HeaderAccessControlRequestHeaders = "Access-Control-Request-Headers"
|
||||
HeaderAccessControlRequestMethod = "Access-Control-Request-Method"
|
||||
HeaderOrigin = "Origin"
|
||||
HeaderTimingAllowOrigin = "Timing-Allow-Origin"
|
||||
HeaderXPermittedCrossDomainPolicies = "X-Permitted-Cross-Domain-Policies"
|
||||
|
||||
// Do Not Track
|
||||
HeaderDNT = "DNT"
|
||||
HeaderTk = "Tk"
|
||||
|
||||
// Downloads
|
||||
HeaderContentDisposition = "Content-Disposition"
|
||||
|
||||
// Message body information
|
||||
HeaderContentEncoding = "Content-Encoding"
|
||||
HeaderContentLanguage = "Content-Language"
|
||||
HeaderContentLength = "Content-Length"
|
||||
HeaderContentLocation = "Content-Location"
|
||||
HeaderContentType = "Content-Type"
|
||||
|
||||
// Proxies
|
||||
HeaderForwarded = "Forwarded"
|
||||
HeaderVia = "Via"
|
||||
HeaderXForwardedFor = "X-Forwarded-For"
|
||||
HeaderXForwardedHost = "X-Forwarded-Host"
|
||||
HeaderXForwardedProto = "X-Forwarded-Proto"
|
||||
|
||||
// Redirects
|
||||
HeaderLocation = "Location"
|
||||
|
||||
// Request context
|
||||
HeaderFrom = "From"
|
||||
HeaderHost = "Host"
|
||||
HeaderReferer = "Referer"
|
||||
HeaderReferrerPolicy = "Referrer-Policy"
|
||||
HeaderUserAgent = "User-Agent"
|
||||
|
||||
// Response context
|
||||
HeaderAllow = "Allow"
|
||||
HeaderServer = "Server"
|
||||
|
||||
// Range requests
|
||||
HeaderAcceptRanges = "Accept-Ranges"
|
||||
HeaderContentRange = "Content-Range"
|
||||
HeaderIfRange = "If-Range"
|
||||
HeaderRange = "Range"
|
||||
|
||||
// Security
|
||||
HeaderContentSecurityPolicy = "Content-Security-Policy"
|
||||
HeaderContentSecurityPolicyReportOnly = "Content-Security-Policy-Report-Only"
|
||||
HeaderCrossOriginResourcePolicy = "Cross-Origin-Resource-Policy"
|
||||
HeaderExpectCT = "Expect-CT"
|
||||
HeaderFeaturePolicy = "Feature-Policy"
|
||||
HeaderPublicKeyPins = "Public-Key-Pins"
|
||||
HeaderPublicKeyPinsReportOnly = "Public-Key-Pins-Report-Only"
|
||||
HeaderStrictTransportSecurity = "Strict-Transport-Security"
|
||||
HeaderUpgradeInsecureRequests = "Upgrade-Insecure-Requests"
|
||||
HeaderXContentTypeOptions = "X-Content-Type-Options"
|
||||
HeaderXDownloadOptions = "X-Download-Options"
|
||||
HeaderXFrameOptions = "X-Frame-Options"
|
||||
HeaderXPoweredBy = "X-Powered-By"
|
||||
HeaderXXSSProtection = "X-XSS-Protection"
|
||||
|
||||
// Server-sent event
|
||||
HeaderLastEventID = "Last-Event-ID"
|
||||
HeaderNEL = "NEL"
|
||||
HeaderPingFrom = "Ping-From"
|
||||
HeaderPingTo = "Ping-To"
|
||||
HeaderReportTo = "Report-To"
|
||||
|
||||
// Transfer coding
|
||||
HeaderTE = "TE"
|
||||
HeaderTrailer = "Trailer"
|
||||
HeaderTransferEncoding = "Transfer-Encoding"
|
||||
|
||||
// WebSockets
|
||||
HeaderSecWebSocketAccept = "Sec-WebSocket-Accept"
|
||||
HeaderSecWebSocketExtensions = "Sec-WebSocket-Extensions"
|
||||
HeaderSecWebSocketKey = "Sec-WebSocket-Key"
|
||||
HeaderSecWebSocketProtocol = "Sec-WebSocket-Protocol"
|
||||
HeaderSecWebSocketVersion = "Sec-WebSocket-Version"
|
||||
|
||||
// Other
|
||||
HeaderAcceptPatch = "Accept-Patch"
|
||||
HeaderAcceptPushPolicy = "Accept-Push-Policy"
|
||||
HeaderAcceptSignature = "Accept-Signature"
|
||||
HeaderAltSvc = "Alt-Svc"
|
||||
HeaderDate = "Date"
|
||||
HeaderIndex = "Index"
|
||||
HeaderLargeAllocation = "Large-Allocation"
|
||||
HeaderLink = "Link"
|
||||
HeaderPushPolicy = "Push-Policy"
|
||||
HeaderRetryAfter = "Retry-After"
|
||||
HeaderServerTiming = "Server-Timing"
|
||||
HeaderSignature = "Signature"
|
||||
HeaderSignedHeaders = "Signed-Headers"
|
||||
HeaderSourceMap = "SourceMap"
|
||||
HeaderUpgrade = "Upgrade"
|
||||
HeaderXDNSPrefetchControl = "X-DNS-Prefetch-Control"
|
||||
HeaderXPingback = "X-Pingback"
|
||||
HeaderXRequestID = "X-Request-ID"
|
||||
HeaderXRequestedWith = "X-Requested-With"
|
||||
HeaderXRobotsTag = "X-Robots-Tag"
|
||||
HeaderXUACompatible = "X-UA-Compatible"
|
||||
)
|
||||
|
||||
const (
|
||||
StatusContinue = 100 // RFC 7231, 6.2.1
|
||||
StatusSwitchingProtocols = 101 // RFC 7231, 6.2.2
|
||||
StatusProcessing = 102 // RFC 2518, 10.1
|
||||
|
||||
StatusOK = 200 // RFC 7231, 6.3.1
|
||||
StatusCreated = 201 // RFC 7231, 6.3.2
|
||||
StatusAccepted = 202 // RFC 7231, 6.3.3
|
||||
StatusNonAuthoritativeInfo = 203 // RFC 7231, 6.3.4
|
||||
StatusNoContent = 204 // RFC 7231, 6.3.5
|
||||
StatusResetContent = 205 // RFC 7231, 6.3.6
|
||||
StatusPartialContent = 206 // RFC 7233, 4.1
|
||||
StatusMultiStatus = 207 // RFC 4918, 11.1
|
||||
StatusAlreadyReported = 208 // RFC 5842, 7.1
|
||||
StatusIMUsed = 226 // RFC 3229, 10.4.1
|
||||
|
||||
StatusMultipleChoices = 300 // RFC 7231, 6.4.1
|
||||
StatusMovedPermanently = 301 // RFC 7231, 6.4.2
|
||||
StatusFound = 302 // RFC 7231, 6.4.3
|
||||
StatusSeeOther = 303 // RFC 7231, 6.4.4
|
||||
StatusNotModified = 304 // RFC 7232, 4.1
|
||||
StatusUseProxy = 305 // RFC 7231, 6.4.5
|
||||
|
||||
StatusTemporaryRedirect = 307 // RFC 7231, 6.4.7
|
||||
StatusPermanentRedirect = 308 // RFC 7538, 3
|
||||
|
||||
StatusBadRequest = 400 // RFC 7231, 6.5.1
|
||||
StatusUnauthorized = 401 // RFC 7235, 3.1
|
||||
StatusPaymentRequired = 402 // RFC 7231, 6.5.2
|
||||
StatusForbidden = 403 // RFC 7231, 6.5.3
|
||||
StatusNotFound = 404 // RFC 7231, 6.5.4
|
||||
StatusMethodNotAllowed = 405 // RFC 7231, 6.5.5
|
||||
StatusNotAcceptable = 406 // RFC 7231, 6.5.6
|
||||
StatusProxyAuthRequired = 407 // RFC 7235, 3.2
|
||||
StatusRequestTimeout = 408 // RFC 7231, 6.5.7
|
||||
StatusConflict = 409 // RFC 7231, 6.5.8
|
||||
StatusGone = 410 // RFC 7231, 6.5.9
|
||||
StatusLengthRequired = 411 // RFC 7231, 6.5.10
|
||||
StatusPreconditionFailed = 412 // RFC 7232, 4.2
|
||||
StatusRequestEntityTooLarge = 413 // RFC 7231, 6.5.11
|
||||
StatusRequestURITooLong = 414 // RFC 7231, 6.5.12
|
||||
StatusUnsupportedMediaType = 415 // RFC 7231, 6.5.13
|
||||
StatusRequestedRangeNotSatisfiable = 416 // RFC 7233, 4.4
|
||||
StatusExpectationFailed = 417 // RFC 7231, 6.5.14
|
||||
StatusTeapot = 418 // RFC 7168, 2.3.3
|
||||
StatusUnprocessableEntity = 422 // RFC 4918, 11.2
|
||||
StatusLocked = 423 // RFC 4918, 11.3
|
||||
StatusFailedDependency = 424 // RFC 4918, 11.4
|
||||
StatusUpgradeRequired = 426 // RFC 7231, 6.5.15
|
||||
StatusPreconditionRequired = 428 // RFC 6585, 3
|
||||
StatusTooManyRequests = 429 // RFC 6585, 4
|
||||
StatusRequestHeaderFieldsTooLarge = 431 // RFC 6585, 5
|
||||
StatusUnavailableForLegalReasons = 451 // RFC 7725, 3
|
||||
|
||||
StatusInternalServerError = 500 // RFC 7231, 6.6.1
|
||||
StatusNotImplemented = 501 // RFC 7231, 6.6.2
|
||||
StatusBadGateway = 502 // RFC 7231, 6.6.3
|
||||
StatusServiceUnavailable = 503 // RFC 7231, 6.6.4
|
||||
StatusGatewayTimeout = 504 // RFC 7231, 6.6.5
|
||||
StatusHTTPVersionNotSupported = 505 // RFC 7231, 6.6.6
|
||||
StatusVariantAlsoNegotiates = 506 // RFC 2295, 8.1
|
||||
StatusInsufficientStorage = 507 // RFC 4918, 11.5
|
||||
StatusLoopDetected = 508 // RFC 5842, 7.2
|
||||
StatusNotExtended = 510 // RFC 2774, 7
|
||||
StatusNetworkAuthenticationRequired = 511 // RFC 6585, 6
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user