Update HTTP status codes (#2203)

* helpers: add HTTP status code 306

* helpers: show numeric HTTP status code instead of status code RFC next to errors

* utils: add HTTP status code 425

* helpers,utils: update list of HTTP status codes
pull/2204/head
leonklingele 2022-11-11 08:40:37 +01:00 committed by GitHub
parent 878c9549d8
commit e388e0edb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 175 additions and 161 deletions

View File

@ -407,65 +407,73 @@ const (
MIMEApplicationJavaScriptCharsetUTF8 = "application/javascript; charset=utf-8" 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 ( const (
StatusContinue = 100 // RFC 7231, 6.2.1 StatusContinue = 100 // RFC 9110, 15.2.1
StatusSwitchingProtocols = 101 // RFC 7231, 6.2.2 StatusSwitchingProtocols = 101 // RFC 9110, 15.2.2
StatusProcessing = 102 // RFC 2518, 10.1 StatusProcessing = 102 // RFC 2518, 10.1
StatusEarlyHints = 103 // RFC 8297 StatusEarlyHints = 103 // RFC 8297
StatusOK = 200 // RFC 7231, 6.3.1
StatusCreated = 201 // RFC 7231, 6.3.2 StatusOK = 200 // RFC 9110, 15.3.1
StatusAccepted = 202 // RFC 7231, 6.3.3 StatusCreated = 201 // RFC 9110, 15.3.2
StatusNonAuthoritativeInformation = 203 // RFC 7231, 6.3.4 StatusAccepted = 202 // RFC 9110, 15.3.3
StatusNoContent = 204 // RFC 7231, 6.3.5 StatusNonAuthoritativeInformation = 203 // RFC 9110, 15.3.4
StatusResetContent = 205 // RFC 7231, 6.3.6 StatusNoContent = 204 // RFC 9110, 15.3.5
StatusPartialContent = 206 // RFC 7233, 4.1 StatusResetContent = 205 // RFC 9110, 15.3.6
StatusMultiStatus = 207 // RFC 4918, 11.1 StatusPartialContent = 206 // RFC 9110, 15.3.7
StatusAlreadyReported = 208 // RFC 5842, 7.1 StatusMultiStatus = 207 // RFC 4918, 11.1
StatusIMUsed = 226 // RFC 3229, 10.4.1 StatusAlreadyReported = 208 // RFC 5842, 7.1
StatusMultipleChoices = 300 // RFC 7231, 6.4.1 StatusIMUsed = 226 // RFC 3229, 10.4.1
StatusMovedPermanently = 301 // RFC 7231, 6.4.2
StatusFound = 302 // RFC 7231, 6.4.3 StatusMultipleChoices = 300 // RFC 9110, 15.4.1
StatusSeeOther = 303 // RFC 7231, 6.4.4 StatusMovedPermanently = 301 // RFC 9110, 15.4.2
StatusNotModified = 304 // RFC 7232, 4.1 StatusFound = 302 // RFC 9110, 15.4.3
StatusUseProxy = 305 // RFC 7231, 6.4.5 StatusSeeOther = 303 // RFC 9110, 15.4.4
StatusTemporaryRedirect = 307 // RFC 7231, 6.4.7 StatusNotModified = 304 // RFC 9110, 15.4.5
StatusPermanentRedirect = 308 // RFC 7538, 3 StatusUseProxy = 305 // RFC 9110, 15.4.6
StatusBadRequest = 400 // RFC 7231, 6.5.1 StatusSwitchProxy = 306 // RFC 9110, 15.4.7 (Unused)
StatusUnauthorized = 401 // RFC 7235, 3.1 StatusTemporaryRedirect = 307 // RFC 9110, 15.4.8
StatusPaymentRequired = 402 // RFC 7231, 6.5.2 StatusPermanentRedirect = 308 // RFC 9110, 15.4.9
StatusForbidden = 403 // RFC 7231, 6.5.3
StatusNotFound = 404 // RFC 7231, 6.5.4 StatusBadRequest = 400 // RFC 9110, 15.5.1
StatusMethodNotAllowed = 405 // RFC 7231, 6.5.5 StatusUnauthorized = 401 // RFC 9110, 15.5.2
StatusNotAcceptable = 406 // RFC 7231, 6.5.6 StatusPaymentRequired = 402 // RFC 9110, 15.5.3
StatusProxyAuthRequired = 407 // RFC 7235, 3.2 StatusForbidden = 403 // RFC 9110, 15.5.4
StatusRequestTimeout = 408 // RFC 7231, 6.5.7 StatusNotFound = 404 // RFC 9110, 15.5.5
StatusConflict = 409 // RFC 7231, 6.5.8 StatusMethodNotAllowed = 405 // RFC 9110, 15.5.6
StatusGone = 410 // RFC 7231, 6.5.9 StatusNotAcceptable = 406 // RFC 9110, 15.5.7
StatusLengthRequired = 411 // RFC 7231, 6.5.10 StatusProxyAuthRequired = 407 // RFC 9110, 15.5.8
StatusPreconditionFailed = 412 // RFC 7232, 4.2 StatusRequestTimeout = 408 // RFC 9110, 15.5.9
StatusRequestEntityTooLarge = 413 // RFC 7231, 6.5.11 StatusConflict = 409 // RFC 9110, 15.5.10
StatusRequestURITooLong = 414 // RFC 7231, 6.5.12 StatusGone = 410 // RFC 9110, 15.5.11
StatusUnsupportedMediaType = 415 // RFC 7231, 6.5.13 StatusLengthRequired = 411 // RFC 9110, 15.5.12
StatusRequestedRangeNotSatisfiable = 416 // RFC 7233, 4.4 StatusPreconditionFailed = 412 // RFC 9110, 15.5.13
StatusExpectationFailed = 417 // RFC 7231, 6.5.14 StatusRequestEntityTooLarge = 413 // RFC 9110, 15.5.14
StatusTeapot = 418 // RFC 7168, 2.3.3 StatusRequestURITooLong = 414 // RFC 9110, 15.5.15
StatusMisdirectedRequest = 421 // RFC 7540, 9.1.2 StatusUnsupportedMediaType = 415 // RFC 9110, 15.5.16
StatusUnprocessableEntity = 422 // RFC 4918, 11.2 StatusRequestedRangeNotSatisfiable = 416 // RFC 9110, 15.5.17
StatusLocked = 423 // RFC 4918, 11.3 StatusExpectationFailed = 417 // RFC 9110, 15.5.18
StatusFailedDependency = 424 // RFC 4918, 11.4 StatusTeapot = 418 // RFC 9110, 15.5.19 (Unused)
StatusTooEarly = 425 // RFC 8470, 5.2. StatusMisdirectedRequest = 421 // RFC 9110, 15.5.20
StatusUpgradeRequired = 426 // RFC 7231, 6.5.15 StatusUnprocessableEntity = 422 // RFC 9110, 15.5.21
StatusPreconditionRequired = 428 // RFC 6585, 3 StatusLocked = 423 // RFC 4918, 11.3
StatusTooManyRequests = 429 // RFC 6585, 4 StatusFailedDependency = 424 // RFC 4918, 11.4
StatusRequestHeaderFieldsTooLarge = 431 // RFC 6585, 5 StatusTooEarly = 425 // RFC 8470, 5.2.
StatusUnavailableForLegalReasons = 451 // RFC 7725, 3 StatusUpgradeRequired = 426 // RFC 9110, 15.5.22
StatusInternalServerError = 500 // RFC 7231, 6.6.1 StatusPreconditionRequired = 428 // RFC 6585, 3
StatusNotImplemented = 501 // RFC 7231, 6.6.2 StatusTooManyRequests = 429 // RFC 6585, 4
StatusBadGateway = 502 // RFC 7231, 6.6.3 StatusRequestHeaderFieldsTooLarge = 431 // RFC 6585, 5
StatusServiceUnavailable = 503 // RFC 7231, 6.6.4 StatusUnavailableForLegalReasons = 451 // RFC 7725, 3
StatusGatewayTimeout = 504 // RFC 7231, 6.6.5
StatusHTTPVersionNotSupported = 505 // RFC 7231, 6.6.6 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 StatusVariantAlsoNegotiates = 506 // RFC 2295, 8.1
StatusInsufficientStorage = 507 // RFC 4918, 11.5 StatusInsufficientStorage = 507 // RFC 4918, 11.5
StatusLoopDetected = 508 // RFC 5842, 7.2 StatusLoopDetected = 508 // RFC 5842, 7.2
@ -475,46 +483,47 @@ const (
// Errors // Errors
var ( var (
ErrBadRequest = NewError(StatusBadRequest) // RFC 7231, 6.5.1 ErrBadRequest = NewError(StatusBadRequest) // 400
ErrUnauthorized = NewError(StatusUnauthorized) // RFC 7235, 3.1 ErrUnauthorized = NewError(StatusUnauthorized) // 401
ErrPaymentRequired = NewError(StatusPaymentRequired) // RFC 7231, 6.5.2 ErrPaymentRequired = NewError(StatusPaymentRequired) // 402
ErrForbidden = NewError(StatusForbidden) // RFC 7231, 6.5.3 ErrForbidden = NewError(StatusForbidden) // 403
ErrNotFound = NewError(StatusNotFound) // RFC 7231, 6.5.4 ErrNotFound = NewError(StatusNotFound) // 404
ErrMethodNotAllowed = NewError(StatusMethodNotAllowed) // RFC 7231, 6.5.5 ErrMethodNotAllowed = NewError(StatusMethodNotAllowed) // 405
ErrNotAcceptable = NewError(StatusNotAcceptable) // RFC 7231, 6.5.6 ErrNotAcceptable = NewError(StatusNotAcceptable) // 406
ErrProxyAuthRequired = NewError(StatusProxyAuthRequired) // RFC 7235, 3.2 ErrProxyAuthRequired = NewError(StatusProxyAuthRequired) // 407
ErrRequestTimeout = NewError(StatusRequestTimeout) // RFC 7231, 6.5.7 ErrRequestTimeout = NewError(StatusRequestTimeout) // 408
ErrConflict = NewError(StatusConflict) // RFC 7231, 6.5.8 ErrConflict = NewError(StatusConflict) // 409
ErrGone = NewError(StatusGone) // RFC 7231, 6.5.9 ErrGone = NewError(StatusGone) // 410
ErrLengthRequired = NewError(StatusLengthRequired) // RFC 7231, 6.5.10 ErrLengthRequired = NewError(StatusLengthRequired) // 411
ErrPreconditionFailed = NewError(StatusPreconditionFailed) // RFC 7232, 4.2 ErrPreconditionFailed = NewError(StatusPreconditionFailed) // 412
ErrRequestEntityTooLarge = NewError(StatusRequestEntityTooLarge) // RFC 7231, 6.5.11 ErrRequestEntityTooLarge = NewError(StatusRequestEntityTooLarge) // 413
ErrRequestURITooLong = NewError(StatusRequestURITooLong) // RFC 7231, 6.5.12 ErrRequestURITooLong = NewError(StatusRequestURITooLong) // 414
ErrUnsupportedMediaType = NewError(StatusUnsupportedMediaType) // RFC 7231, 6.5.13 ErrUnsupportedMediaType = NewError(StatusUnsupportedMediaType) // 415
ErrRequestedRangeNotSatisfiable = NewError(StatusRequestedRangeNotSatisfiable) // RFC 7233, 4.4 ErrRequestedRangeNotSatisfiable = NewError(StatusRequestedRangeNotSatisfiable) // 416
ErrExpectationFailed = NewError(StatusExpectationFailed) // RFC 7231, 6.5.14 ErrExpectationFailed = NewError(StatusExpectationFailed) // 417
ErrTeapot = NewError(StatusTeapot) // RFC 7168, 2.3.3 ErrTeapot = NewError(StatusTeapot) // 418
ErrMisdirectedRequest = NewError(StatusMisdirectedRequest) // RFC 7540, 9.1.2 ErrMisdirectedRequest = NewError(StatusMisdirectedRequest) // 421
ErrUnprocessableEntity = NewError(StatusUnprocessableEntity) // RFC 4918, 11.2 ErrUnprocessableEntity = NewError(StatusUnprocessableEntity) // 422
ErrLocked = NewError(StatusLocked) // RFC 4918, 11.3 ErrLocked = NewError(StatusLocked) // 423
ErrFailedDependency = NewError(StatusFailedDependency) // RFC 4918, 11.4 ErrFailedDependency = NewError(StatusFailedDependency) // 424
ErrTooEarly = NewError(StatusTooEarly) // RFC 8470, 5.2. ErrTooEarly = NewError(StatusTooEarly) // 425
ErrUpgradeRequired = NewError(StatusUpgradeRequired) // RFC 7231, 6.5.15 ErrUpgradeRequired = NewError(StatusUpgradeRequired) // 426
ErrPreconditionRequired = NewError(StatusPreconditionRequired) // RFC 6585, 3 ErrPreconditionRequired = NewError(StatusPreconditionRequired) // 428
ErrTooManyRequests = NewError(StatusTooManyRequests) // RFC 6585, 4 ErrTooManyRequests = NewError(StatusTooManyRequests) // 429
ErrRequestHeaderFieldsTooLarge = NewError(StatusRequestHeaderFieldsTooLarge) // RFC 6585, 5 ErrRequestHeaderFieldsTooLarge = NewError(StatusRequestHeaderFieldsTooLarge) // 431
ErrUnavailableForLegalReasons = NewError(StatusUnavailableForLegalReasons) // RFC 7725, 3 ErrUnavailableForLegalReasons = NewError(StatusUnavailableForLegalReasons) // 451
ErrInternalServerError = NewError(StatusInternalServerError) // RFC 7231, 6.6.1
ErrNotImplemented = NewError(StatusNotImplemented) // RFC 7231, 6.6.2 ErrInternalServerError = NewError(StatusInternalServerError) // 500
ErrBadGateway = NewError(StatusBadGateway) // RFC 7231, 6.6.3 ErrNotImplemented = NewError(StatusNotImplemented) // 501
ErrServiceUnavailable = NewError(StatusServiceUnavailable) // RFC 7231, 6.6.4 ErrBadGateway = NewError(StatusBadGateway) // 502
ErrGatewayTimeout = NewError(StatusGatewayTimeout) // RFC 7231, 6.6.5 ErrServiceUnavailable = NewError(StatusServiceUnavailable) // 503
ErrHTTPVersionNotSupported = NewError(StatusHTTPVersionNotSupported) // RFC 7231, 6.6.6 ErrGatewayTimeout = NewError(StatusGatewayTimeout) // 504
ErrVariantAlsoNegotiates = NewError(StatusVariantAlsoNegotiates) // RFC 2295, 8.1 ErrHTTPVersionNotSupported = NewError(StatusHTTPVersionNotSupported) // 505
ErrInsufficientStorage = NewError(StatusInsufficientStorage) // RFC 4918, 11.5 ErrVariantAlsoNegotiates = NewError(StatusVariantAlsoNegotiates) // 506
ErrLoopDetected = NewError(StatusLoopDetected) // RFC 5842, 7.2 ErrInsufficientStorage = NewError(StatusInsufficientStorage) // 507
ErrNotExtended = NewError(StatusNotExtended) // RFC 2774, 7 ErrLoopDetected = NewError(StatusLoopDetected) // 508
ErrNetworkAuthenticationRequired = NewError(StatusNetworkAuthenticationRequired) // RFC 6585, 6 ErrNotExtended = NewError(StatusNotExtended) // 510
ErrNetworkAuthenticationRequired = NewError(StatusNetworkAuthenticationRequired) // 511
) )
// HTTP Headers were copied from net/http. // HTTP Headers were copied from net/http.

View File

@ -66,70 +66,75 @@ func StatusMessage(status int) string {
return statusMessage[status] return statusMessage[status]
} }
// HTTP status codes were copied from net/http. // NOTE: Keep this in sync with the status code list
var statusMessage = []string{ var statusMessage = []string{
100: "Continue", 100: "Continue", // StatusContinue
101: "Switching Protocols", 101: "Switching Protocols", // StatusSwitchingProtocols
102: "Processing", 102: "Processing", // StatusProcessing
103: "Early Hints", 103: "Early Hints", // StatusEarlyHints
200: "OK",
201: "Created", 200: "OK", // StatusOK
202: "Accepted", 201: "Created", // StatusCreated
203: "Non-Authoritative Information", 202: "Accepted", // StatusAccepted
204: "No Content", 203: "Non-Authoritative Information", // StatusNonAuthoritativeInformation
205: "Reset Content", 204: "No Content", // StatusNoContent
206: "Partial Content", 205: "Reset Content", // StatusResetContent
207: "Multi-Status", 206: "Partial Content", // StatusPartialContent
208: "Already Reported", 207: "Multi-Status", // StatusMultiStatus
226: "IM Used", 208: "Already Reported", // StatusAlreadyReported
300: "Multiple Choices", 226: "IM Used", // StatusIMUsed
301: "Moved Permanently",
302: "Found", 300: "Multiple Choices", // StatusMultipleChoices
303: "See Other", 301: "Moved Permanently", // StatusMovedPermanently
304: "Not Modified", 302: "Found", // StatusFound
305: "Use Proxy", 303: "See Other", // StatusSeeOther
306: "Switch Proxy", 304: "Not Modified", // StatusNotModified
307: "Temporary Redirect", 305: "Use Proxy", // StatusUseProxy
308: "Permanent Redirect", 306: "Switch Proxy", // StatusSwitchProxy
400: "Bad Request", 307: "Temporary Redirect", // StatusTemporaryRedirect
401: "Unauthorized", 308: "Permanent Redirect", // StatusPermanentRedirect
402: "Payment Required",
403: "Forbidden", 400: "Bad Request", // StatusBadRequest
404: "Not Found", 401: "Unauthorized", // StatusUnauthorized
405: "Method Not Allowed", 402: "Payment Required", // StatusPaymentRequired
406: "Not Acceptable", 403: "Forbidden", // StatusForbidden
407: "Proxy Authentication Required", 404: "Not Found", // StatusNotFound
408: "Request Timeout", 405: "Method Not Allowed", // StatusMethodNotAllowed
409: "Conflict", 406: "Not Acceptable", // StatusNotAcceptable
410: "Gone", 407: "Proxy Authentication Required", // StatusProxyAuthRequired
411: "Length Required", 408: "Request Timeout", // StatusRequestTimeout
412: "Precondition Failed", 409: "Conflict", // StatusConflict
413: "Request Entity Too Large", 410: "Gone", // StatusGone
414: "Request URI Too Long", 411: "Length Required", // StatusLengthRequired
415: "Unsupported Media Type", 412: "Precondition Failed", // StatusPreconditionFailed
416: "Requested Range Not Satisfiable", 413: "Request Entity Too Large", // StatusRequestEntityTooLarge
417: "Expectation Failed", 414: "Request URI Too Long", // StatusRequestURITooLong
418: "I'm a teapot", 415: "Unsupported Media Type", // StatusUnsupportedMediaType
421: "Misdirected Request", 416: "Requested Range Not Satisfiable", // StatusRequestedRangeNotSatisfiable
422: "Unprocessable Entity", 417: "Expectation Failed", // StatusExpectationFailed
423: "Locked", 418: "I'm a teapot", // StatusTeapot
424: "Failed Dependency", 421: "Misdirected Request", // StatusMisdirectedRequest
426: "Upgrade Required", 422: "Unprocessable Entity", // StatusUnprocessableEntity
428: "Precondition Required", 423: "Locked", // StatusLocked
429: "Too Many Requests", 424: "Failed Dependency", // StatusFailedDependency
431: "Request Header Fields Too Large", 425: "Too Early", // StatusTooEarly
451: "Unavailable For Legal Reasons", 426: "Upgrade Required", // StatusUpgradeRequired
500: "Internal Server Error", 428: "Precondition Required", // StatusPreconditionRequired
501: "Not Implemented", 429: "Too Many Requests", // StatusTooManyRequests
502: "Bad Gateway", 431: "Request Header Fields Too Large", // StatusRequestHeaderFieldsTooLarge
503: "Service Unavailable", 451: "Unavailable For Legal Reasons", // StatusUnavailableForLegalReasons
504: "Gateway Timeout",
505: "HTTP Version Not Supported", 500: "Internal Server Error", // StatusInternalServerError
506: "Variant Also Negotiates", 501: "Not Implemented", // StatusNotImplemented
507: "Insufficient Storage", 502: "Bad Gateway", // StatusBadGateway
508: "Loop Detected", 503: "Service Unavailable", // StatusServiceUnavailable
510: "Not Extended", 504: "Gateway Timeout", // StatusGatewayTimeout
511: "Network Authentication Required", 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: // MIME types were copied from https://github.com/nginx/nginx/blob/67d2a9541826ecd5db97d604f23460210fd3e517/conf/mime.types with the following updates: