diff --git a/helpers.go b/helpers.go index aa9511da82..11364e7334 100644 --- a/helpers.go +++ b/helpers.go @@ -407,65 +407,73 @@ const ( MIMEApplicationJavaScriptCharsetUTF8 = "application/javascript; charset=utf-8" ) -// HTTP status codes were copied from net/http. +// HTTP status codes were copied from https://github.com/nginx/nginx/blob/67d2a9541826ecd5db97d604f23460210fd3e517/conf/mime.types with the following updates: +// - Rename StatusNonAuthoritativeInfo to StatusNonAuthoritativeInformation +// - Add StatusSwitchProxy (306) +// NOTE: Keep this list in sync with statusMessage const ( - StatusContinue = 100 // RFC 7231, 6.2.1 - StatusSwitchingProtocols = 101 // RFC 7231, 6.2.2 - StatusProcessing = 102 // RFC 2518, 10.1 - StatusEarlyHints = 103 // RFC 8297 - StatusOK = 200 // RFC 7231, 6.3.1 - StatusCreated = 201 // RFC 7231, 6.3.2 - StatusAccepted = 202 // RFC 7231, 6.3.3 - StatusNonAuthoritativeInformation = 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 - StatusMisdirectedRequest = 421 // RFC 7540, 9.1.2 - StatusUnprocessableEntity = 422 // RFC 4918, 11.2 - StatusLocked = 423 // RFC 4918, 11.3 - StatusFailedDependency = 424 // RFC 4918, 11.4 - StatusTooEarly = 425 // RFC 8470, 5.2. - 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 + StatusContinue = 100 // RFC 9110, 15.2.1 + StatusSwitchingProtocols = 101 // RFC 9110, 15.2.2 + StatusProcessing = 102 // RFC 2518, 10.1 + StatusEarlyHints = 103 // RFC 8297 + + StatusOK = 200 // RFC 9110, 15.3.1 + StatusCreated = 201 // RFC 9110, 15.3.2 + StatusAccepted = 202 // RFC 9110, 15.3.3 + StatusNonAuthoritativeInformation = 203 // RFC 9110, 15.3.4 + StatusNoContent = 204 // RFC 9110, 15.3.5 + StatusResetContent = 205 // RFC 9110, 15.3.6 + StatusPartialContent = 206 // RFC 9110, 15.3.7 + StatusMultiStatus = 207 // RFC 4918, 11.1 + StatusAlreadyReported = 208 // RFC 5842, 7.1 + StatusIMUsed = 226 // RFC 3229, 10.4.1 + + StatusMultipleChoices = 300 // RFC 9110, 15.4.1 + StatusMovedPermanently = 301 // RFC 9110, 15.4.2 + StatusFound = 302 // RFC 9110, 15.4.3 + StatusSeeOther = 303 // RFC 9110, 15.4.4 + StatusNotModified = 304 // RFC 9110, 15.4.5 + StatusUseProxy = 305 // RFC 9110, 15.4.6 + StatusSwitchProxy = 306 // RFC 9110, 15.4.7 (Unused) + StatusTemporaryRedirect = 307 // RFC 9110, 15.4.8 + StatusPermanentRedirect = 308 // RFC 9110, 15.4.9 + + StatusBadRequest = 400 // RFC 9110, 15.5.1 + StatusUnauthorized = 401 // RFC 9110, 15.5.2 + StatusPaymentRequired = 402 // RFC 9110, 15.5.3 + StatusForbidden = 403 // RFC 9110, 15.5.4 + StatusNotFound = 404 // RFC 9110, 15.5.5 + StatusMethodNotAllowed = 405 // RFC 9110, 15.5.6 + StatusNotAcceptable = 406 // RFC 9110, 15.5.7 + StatusProxyAuthRequired = 407 // RFC 9110, 15.5.8 + StatusRequestTimeout = 408 // RFC 9110, 15.5.9 + StatusConflict = 409 // RFC 9110, 15.5.10 + StatusGone = 410 // RFC 9110, 15.5.11 + StatusLengthRequired = 411 // RFC 9110, 15.5.12 + StatusPreconditionFailed = 412 // RFC 9110, 15.5.13 + StatusRequestEntityTooLarge = 413 // RFC 9110, 15.5.14 + StatusRequestURITooLong = 414 // RFC 9110, 15.5.15 + StatusUnsupportedMediaType = 415 // RFC 9110, 15.5.16 + StatusRequestedRangeNotSatisfiable = 416 // RFC 9110, 15.5.17 + StatusExpectationFailed = 417 // RFC 9110, 15.5.18 + StatusTeapot = 418 // RFC 9110, 15.5.19 (Unused) + StatusMisdirectedRequest = 421 // RFC 9110, 15.5.20 + StatusUnprocessableEntity = 422 // RFC 9110, 15.5.21 + StatusLocked = 423 // RFC 4918, 11.3 + StatusFailedDependency = 424 // RFC 4918, 11.4 + StatusTooEarly = 425 // RFC 8470, 5.2. + StatusUpgradeRequired = 426 // RFC 9110, 15.5.22 + StatusPreconditionRequired = 428 // RFC 6585, 3 + StatusTooManyRequests = 429 // RFC 6585, 4 + StatusRequestHeaderFieldsTooLarge = 431 // RFC 6585, 5 + StatusUnavailableForLegalReasons = 451 // RFC 7725, 3 + + StatusInternalServerError = 500 // RFC 9110, 15.6.1 + StatusNotImplemented = 501 // RFC 9110, 15.6.2 + StatusBadGateway = 502 // RFC 9110, 15.6.3 + StatusServiceUnavailable = 503 // RFC 9110, 15.6.4 + StatusGatewayTimeout = 504 // RFC 9110, 15.6.5 + StatusHTTPVersionNotSupported = 505 // RFC 9110, 15.6.6 StatusVariantAlsoNegotiates = 506 // RFC 2295, 8.1 StatusInsufficientStorage = 507 // RFC 4918, 11.5 StatusLoopDetected = 508 // RFC 5842, 7.2 @@ -475,46 +483,47 @@ const ( // Errors var ( - ErrBadRequest = NewError(StatusBadRequest) // RFC 7231, 6.5.1 - ErrUnauthorized = NewError(StatusUnauthorized) // RFC 7235, 3.1 - ErrPaymentRequired = NewError(StatusPaymentRequired) // RFC 7231, 6.5.2 - ErrForbidden = NewError(StatusForbidden) // RFC 7231, 6.5.3 - ErrNotFound = NewError(StatusNotFound) // RFC 7231, 6.5.4 - ErrMethodNotAllowed = NewError(StatusMethodNotAllowed) // RFC 7231, 6.5.5 - ErrNotAcceptable = NewError(StatusNotAcceptable) // RFC 7231, 6.5.6 - ErrProxyAuthRequired = NewError(StatusProxyAuthRequired) // RFC 7235, 3.2 - ErrRequestTimeout = NewError(StatusRequestTimeout) // RFC 7231, 6.5.7 - ErrConflict = NewError(StatusConflict) // RFC 7231, 6.5.8 - ErrGone = NewError(StatusGone) // RFC 7231, 6.5.9 - ErrLengthRequired = NewError(StatusLengthRequired) // RFC 7231, 6.5.10 - ErrPreconditionFailed = NewError(StatusPreconditionFailed) // RFC 7232, 4.2 - ErrRequestEntityTooLarge = NewError(StatusRequestEntityTooLarge) // RFC 7231, 6.5.11 - ErrRequestURITooLong = NewError(StatusRequestURITooLong) // RFC 7231, 6.5.12 - ErrUnsupportedMediaType = NewError(StatusUnsupportedMediaType) // RFC 7231, 6.5.13 - ErrRequestedRangeNotSatisfiable = NewError(StatusRequestedRangeNotSatisfiable) // RFC 7233, 4.4 - ErrExpectationFailed = NewError(StatusExpectationFailed) // RFC 7231, 6.5.14 - ErrTeapot = NewError(StatusTeapot) // RFC 7168, 2.3.3 - ErrMisdirectedRequest = NewError(StatusMisdirectedRequest) // RFC 7540, 9.1.2 - ErrUnprocessableEntity = NewError(StatusUnprocessableEntity) // RFC 4918, 11.2 - ErrLocked = NewError(StatusLocked) // RFC 4918, 11.3 - ErrFailedDependency = NewError(StatusFailedDependency) // RFC 4918, 11.4 - ErrTooEarly = NewError(StatusTooEarly) // RFC 8470, 5.2. - ErrUpgradeRequired = NewError(StatusUpgradeRequired) // RFC 7231, 6.5.15 - ErrPreconditionRequired = NewError(StatusPreconditionRequired) // RFC 6585, 3 - ErrTooManyRequests = NewError(StatusTooManyRequests) // RFC 6585, 4 - ErrRequestHeaderFieldsTooLarge = NewError(StatusRequestHeaderFieldsTooLarge) // RFC 6585, 5 - ErrUnavailableForLegalReasons = NewError(StatusUnavailableForLegalReasons) // RFC 7725, 3 - ErrInternalServerError = NewError(StatusInternalServerError) // RFC 7231, 6.6.1 - ErrNotImplemented = NewError(StatusNotImplemented) // RFC 7231, 6.6.2 - ErrBadGateway = NewError(StatusBadGateway) // RFC 7231, 6.6.3 - ErrServiceUnavailable = NewError(StatusServiceUnavailable) // RFC 7231, 6.6.4 - ErrGatewayTimeout = NewError(StatusGatewayTimeout) // RFC 7231, 6.6.5 - ErrHTTPVersionNotSupported = NewError(StatusHTTPVersionNotSupported) // RFC 7231, 6.6.6 - ErrVariantAlsoNegotiates = NewError(StatusVariantAlsoNegotiates) // RFC 2295, 8.1 - ErrInsufficientStorage = NewError(StatusInsufficientStorage) // RFC 4918, 11.5 - ErrLoopDetected = NewError(StatusLoopDetected) // RFC 5842, 7.2 - ErrNotExtended = NewError(StatusNotExtended) // RFC 2774, 7 - ErrNetworkAuthenticationRequired = NewError(StatusNetworkAuthenticationRequired) // RFC 6585, 6 + ErrBadRequest = NewError(StatusBadRequest) // 400 + ErrUnauthorized = NewError(StatusUnauthorized) // 401 + ErrPaymentRequired = NewError(StatusPaymentRequired) // 402 + ErrForbidden = NewError(StatusForbidden) // 403 + ErrNotFound = NewError(StatusNotFound) // 404 + ErrMethodNotAllowed = NewError(StatusMethodNotAllowed) // 405 + ErrNotAcceptable = NewError(StatusNotAcceptable) // 406 + ErrProxyAuthRequired = NewError(StatusProxyAuthRequired) // 407 + ErrRequestTimeout = NewError(StatusRequestTimeout) // 408 + ErrConflict = NewError(StatusConflict) // 409 + ErrGone = NewError(StatusGone) // 410 + ErrLengthRequired = NewError(StatusLengthRequired) // 411 + ErrPreconditionFailed = NewError(StatusPreconditionFailed) // 412 + ErrRequestEntityTooLarge = NewError(StatusRequestEntityTooLarge) // 413 + ErrRequestURITooLong = NewError(StatusRequestURITooLong) // 414 + ErrUnsupportedMediaType = NewError(StatusUnsupportedMediaType) // 415 + ErrRequestedRangeNotSatisfiable = NewError(StatusRequestedRangeNotSatisfiable) // 416 + ErrExpectationFailed = NewError(StatusExpectationFailed) // 417 + ErrTeapot = NewError(StatusTeapot) // 418 + ErrMisdirectedRequest = NewError(StatusMisdirectedRequest) // 421 + ErrUnprocessableEntity = NewError(StatusUnprocessableEntity) // 422 + ErrLocked = NewError(StatusLocked) // 423 + ErrFailedDependency = NewError(StatusFailedDependency) // 424 + ErrTooEarly = NewError(StatusTooEarly) // 425 + ErrUpgradeRequired = NewError(StatusUpgradeRequired) // 426 + ErrPreconditionRequired = NewError(StatusPreconditionRequired) // 428 + ErrTooManyRequests = NewError(StatusTooManyRequests) // 429 + ErrRequestHeaderFieldsTooLarge = NewError(StatusRequestHeaderFieldsTooLarge) // 431 + ErrUnavailableForLegalReasons = NewError(StatusUnavailableForLegalReasons) // 451 + + ErrInternalServerError = NewError(StatusInternalServerError) // 500 + ErrNotImplemented = NewError(StatusNotImplemented) // 501 + ErrBadGateway = NewError(StatusBadGateway) // 502 + ErrServiceUnavailable = NewError(StatusServiceUnavailable) // 503 + ErrGatewayTimeout = NewError(StatusGatewayTimeout) // 504 + ErrHTTPVersionNotSupported = NewError(StatusHTTPVersionNotSupported) // 505 + ErrVariantAlsoNegotiates = NewError(StatusVariantAlsoNegotiates) // 506 + ErrInsufficientStorage = NewError(StatusInsufficientStorage) // 507 + ErrLoopDetected = NewError(StatusLoopDetected) // 508 + ErrNotExtended = NewError(StatusNotExtended) // 510 + ErrNetworkAuthenticationRequired = NewError(StatusNetworkAuthenticationRequired) // 511 ) // HTTP Headers were copied from net/http. diff --git a/utils/http.go b/utils/http.go index fc52402315..bdcd834c98 100644 --- a/utils/http.go +++ b/utils/http.go @@ -66,70 +66,75 @@ func StatusMessage(status int) string { return statusMessage[status] } -// HTTP status codes were copied from net/http. +// NOTE: Keep this in sync with the status code list 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", + 100: "Continue", // StatusContinue + 101: "Switching Protocols", // StatusSwitchingProtocols + 102: "Processing", // StatusProcessing + 103: "Early Hints", // StatusEarlyHints + + 200: "OK", // StatusOK + 201: "Created", // StatusCreated + 202: "Accepted", // StatusAccepted + 203: "Non-Authoritative Information", // StatusNonAuthoritativeInformation + 204: "No Content", // StatusNoContent + 205: "Reset Content", // StatusResetContent + 206: "Partial Content", // StatusPartialContent + 207: "Multi-Status", // StatusMultiStatus + 208: "Already Reported", // StatusAlreadyReported + 226: "IM Used", // StatusIMUsed + + 300: "Multiple Choices", // StatusMultipleChoices + 301: "Moved Permanently", // StatusMovedPermanently + 302: "Found", // StatusFound + 303: "See Other", // StatusSeeOther + 304: "Not Modified", // StatusNotModified + 305: "Use Proxy", // StatusUseProxy + 306: "Switch Proxy", // StatusSwitchProxy + 307: "Temporary Redirect", // StatusTemporaryRedirect + 308: "Permanent Redirect", // StatusPermanentRedirect + + 400: "Bad Request", // StatusBadRequest + 401: "Unauthorized", // StatusUnauthorized + 402: "Payment Required", // StatusPaymentRequired + 403: "Forbidden", // StatusForbidden + 404: "Not Found", // StatusNotFound + 405: "Method Not Allowed", // StatusMethodNotAllowed + 406: "Not Acceptable", // StatusNotAcceptable + 407: "Proxy Authentication Required", // StatusProxyAuthRequired + 408: "Request Timeout", // StatusRequestTimeout + 409: "Conflict", // StatusConflict + 410: "Gone", // StatusGone + 411: "Length Required", // StatusLengthRequired + 412: "Precondition Failed", // StatusPreconditionFailed + 413: "Request Entity Too Large", // StatusRequestEntityTooLarge + 414: "Request URI Too Long", // StatusRequestURITooLong + 415: "Unsupported Media Type", // StatusUnsupportedMediaType + 416: "Requested Range Not Satisfiable", // StatusRequestedRangeNotSatisfiable + 417: "Expectation Failed", // StatusExpectationFailed + 418: "I'm a teapot", // StatusTeapot + 421: "Misdirected Request", // StatusMisdirectedRequest + 422: "Unprocessable Entity", // StatusUnprocessableEntity + 423: "Locked", // StatusLocked + 424: "Failed Dependency", // StatusFailedDependency + 425: "Too Early", // StatusTooEarly + 426: "Upgrade Required", // StatusUpgradeRequired + 428: "Precondition Required", // StatusPreconditionRequired + 429: "Too Many Requests", // StatusTooManyRequests + 431: "Request Header Fields Too Large", // StatusRequestHeaderFieldsTooLarge + 451: "Unavailable For Legal Reasons", // StatusUnavailableForLegalReasons + + 500: "Internal Server Error", // StatusInternalServerError + 501: "Not Implemented", // StatusNotImplemented + 502: "Bad Gateway", // StatusBadGateway + 503: "Service Unavailable", // StatusServiceUnavailable + 504: "Gateway Timeout", // StatusGatewayTimeout + 505: "HTTP Version Not Supported", // StatusHTTPVersionNotSupported + 506: "Variant Also Negotiates", // StatusVariantAlsoNegotiates + 507: "Insufficient Storage", // StatusInsufficientStorage + 508: "Loop Detected", // StatusLoopDetected + 510: "Not Extended", // StatusNotExtended + 511: "Network Authentication Required", // StatusNetworkAuthenticationRequired } // MIME types were copied from https://github.com/nginx/nginx/blob/67d2a9541826ecd5db97d604f23460210fd3e517/conf/mime.types with the following updates: