mirror of
https://github.com/soypat/lneto.git
synced 2026-08-16 12:53:26 +00:00
add http/httphi
This commit is contained in:
@@ -0,0 +1,271 @@
|
||||
package httphi
|
||||
|
||||
// StatusText returns a text for the HTTP status code. It returns the empty
|
||||
// string if the code is unknown.
|
||||
func StatusText(code int) string {
|
||||
switch status(code) {
|
||||
case StatusContinue:
|
||||
return "Continue"
|
||||
case StatusSwitchingProtocols:
|
||||
return "Switching Protocols"
|
||||
case StatusProcessing:
|
||||
return "Processing"
|
||||
case StatusEarlyHints:
|
||||
return "Early Hints"
|
||||
case StatusOK:
|
||||
return "OK"
|
||||
case StatusCreated:
|
||||
return "Created"
|
||||
case StatusAccepted:
|
||||
return "Accepted"
|
||||
case StatusNonAuthoritativeInfo:
|
||||
return "Non-Authoritative Information"
|
||||
case StatusNoContent:
|
||||
return "No Content"
|
||||
case StatusResetContent:
|
||||
return "Reset Content"
|
||||
case StatusPartialContent:
|
||||
return "Partial Content"
|
||||
case StatusMultiStatus:
|
||||
return "Multi-Status"
|
||||
case StatusAlreadyReported:
|
||||
return "Already Reported"
|
||||
case StatusIMUsed:
|
||||
return "IM Used"
|
||||
case StatusMultipleChoices:
|
||||
return "Multiple Choices"
|
||||
case StatusMovedPermanently:
|
||||
return "Moved Permanently"
|
||||
case StatusFound:
|
||||
return "Found"
|
||||
case StatusSeeOther:
|
||||
return "See Other"
|
||||
case StatusNotModified:
|
||||
return "Not Modified"
|
||||
case StatusUseProxy:
|
||||
return "Use Proxy"
|
||||
case StatusTemporaryRedirect:
|
||||
return "Temporary Redirect"
|
||||
case StatusPermanentRedirect:
|
||||
return "Permanent Redirect"
|
||||
case StatusBadRequest:
|
||||
return "Bad Request"
|
||||
case StatusUnauthorized:
|
||||
return "Unauthorized"
|
||||
case StatusPaymentRequired:
|
||||
return "Payment Required"
|
||||
case StatusForbidden:
|
||||
return "Forbidden"
|
||||
case StatusNotFound:
|
||||
return "Not Found"
|
||||
case StatusMethodNotAllowed:
|
||||
return "Method Not Allowed"
|
||||
case StatusNotAcceptable:
|
||||
return "Not Acceptable"
|
||||
case StatusProxyAuthRequired:
|
||||
return "Proxy Authentication Required"
|
||||
case StatusRequestTimeout:
|
||||
return "Request Timeout"
|
||||
case StatusConflict:
|
||||
return "Conflict"
|
||||
case StatusGone:
|
||||
return "Gone"
|
||||
case StatusLengthRequired:
|
||||
return "Length Required"
|
||||
case StatusPreconditionFailed:
|
||||
return "Precondition Failed"
|
||||
case StatusRequestEntityTooLarge:
|
||||
return "Request Entity Too Large"
|
||||
case StatusRequestURITooLong:
|
||||
return "Request URI Too Long"
|
||||
case StatusUnsupportedMediaType:
|
||||
return "Unsupported Media Type"
|
||||
case StatusRequestedRangeNotSatisfiable:
|
||||
return "Requested Range Not Satisfiable"
|
||||
case StatusExpectationFailed:
|
||||
return "Expectation Failed"
|
||||
case StatusTeapot:
|
||||
return "I'm a teapot"
|
||||
case StatusMisdirectedRequest:
|
||||
return "Misdirected Request"
|
||||
case StatusUnprocessableEntity:
|
||||
return "Unprocessable Entity"
|
||||
case StatusLocked:
|
||||
return "Locked"
|
||||
case StatusFailedDependency:
|
||||
return "Failed Dependency"
|
||||
case StatusTooEarly:
|
||||
return "Too Early"
|
||||
case StatusUpgradeRequired:
|
||||
return "Upgrade Required"
|
||||
case StatusPreconditionRequired:
|
||||
return "Precondition Required"
|
||||
case StatusTooManyRequests:
|
||||
return "Too Many Requests"
|
||||
case StatusRequestHeaderFieldsTooLarge:
|
||||
return "Request Header Fields Too Large"
|
||||
case StatusUnavailableForLegalReasons:
|
||||
return "Unavailable For Legal Reasons"
|
||||
case StatusInternalServerError:
|
||||
return "Internal Server Error"
|
||||
case StatusNotImplemented:
|
||||
return "Not Implemented"
|
||||
case StatusBadGateway:
|
||||
return "Bad Gateway"
|
||||
case StatusServiceUnavailable:
|
||||
return "Service Unavailable"
|
||||
case StatusGatewayTimeout:
|
||||
return "Gateway Timeout"
|
||||
case StatusHTTPVersionNotSupported:
|
||||
return "HTTP Version Not Supported"
|
||||
case StatusVariantAlsoNegotiates:
|
||||
return "Variant Also Negotiates"
|
||||
case StatusInsufficientStorage:
|
||||
return "Insufficient Storage"
|
||||
case StatusLoopDetected:
|
||||
return "Loop Detected"
|
||||
case StatusNotExtended:
|
||||
return "Not Extended"
|
||||
case StatusNetworkAuthenticationRequired:
|
||||
return "Network Authentication Required"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
type status int
|
||||
|
||||
// HTTP status codes as registered with IANA.
|
||||
// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
|
||||
const (
|
||||
// RFC 9110, 15.2.1
|
||||
StatusContinue status = 100 // Continue
|
||||
// RFC 9110, 15.2.2
|
||||
StatusSwitchingProtocols status = 101 // Switching Protocols
|
||||
// RFC 2518, 10.1
|
||||
StatusProcessing status = 102 // Processing
|
||||
// RFC 8297
|
||||
StatusEarlyHints status = 103 // Early Hints
|
||||
|
||||
// RFC 9110, 15.3.1
|
||||
StatusOK status = 200 // OK
|
||||
// RFC 9110, 15.3.2
|
||||
StatusCreated status = 201 // Created
|
||||
// RFC 9110, 15.3.3
|
||||
StatusAccepted status = 202 // Accepted
|
||||
// RFC 9110, 15.3.4
|
||||
StatusNonAuthoritativeInfo status = 203 // Non-Authoritative Information
|
||||
// RFC 9110, 15.3.5
|
||||
StatusNoContent status = 204 // No Content
|
||||
// RFC 9110, 15.3.6
|
||||
StatusResetContent status = 205 // Reset Content
|
||||
// RFC 9110, 15.3.7
|
||||
StatusPartialContent status = 206 // Partial Content
|
||||
// RFC 4918, 11.1
|
||||
StatusMultiStatus status = 207 // Multi-Status
|
||||
// RFC 5842, 7.1
|
||||
StatusAlreadyReported status = 208 // Already Reported
|
||||
// RFC 3229, 10.4.1
|
||||
StatusIMUsed status = 226 // IM Used
|
||||
|
||||
// RFC 9110, 15.4.1
|
||||
StatusMultipleChoices status = 300 // Multiple Choices
|
||||
// RFC 9110, 15.4.2
|
||||
StatusMovedPermanently status = 301 // Moved Permanently
|
||||
// RFC 9110, 15.4.3
|
||||
StatusFound status = 302 // Found
|
||||
// RFC 9110, 15.4.4
|
||||
StatusSeeOther status = 303 // See Other
|
||||
// RFC 9110, 15.4.5
|
||||
StatusNotModified status = 304 // Not Modified
|
||||
// RFC 9110, 15.4.6
|
||||
StatusUseProxy status = 305 // Use Proxy
|
||||
// RFC 9110, 15.4.7 (Unused)
|
||||
_ status = 306
|
||||
// RFC 9110, 15.4.8
|
||||
StatusTemporaryRedirect status = 307 // Temporary Redirect
|
||||
// RFC 9110, 15.4.9
|
||||
StatusPermanentRedirect status = 308 // Permanent Redirect
|
||||
|
||||
// RFC 9110, 15.5.1
|
||||
StatusBadRequest status = 400 // Bad Request
|
||||
// RFC 9110, 15.5.2
|
||||
StatusUnauthorized status = 401 // Unauthorized
|
||||
// RFC 9110, 15.5.3
|
||||
StatusPaymentRequired status = 402 // Payment Required
|
||||
// RFC 9110, 15.5.4
|
||||
StatusForbidden status = 403 // Forbidden
|
||||
// RFC 9110, 15.5.5
|
||||
StatusNotFound status = 404 // Not Found
|
||||
// RFC 9110, 15.5.6
|
||||
StatusMethodNotAllowed status = 405 // Method Not Allowed
|
||||
// RFC 9110, 15.5.7
|
||||
StatusNotAcceptable status = 406 // Not Acceptable
|
||||
// RFC 9110, 15.5.8
|
||||
StatusProxyAuthRequired status = 407 // Proxy Authentication Required
|
||||
// RFC 9110, 15.5.9
|
||||
StatusRequestTimeout status = 408 // Request Timeout
|
||||
// RFC 9110, 15.5.10
|
||||
StatusConflict status = 409 // Conflict
|
||||
// RFC 9110, 15.5.11
|
||||
StatusGone status = 410 // Gone
|
||||
// RFC 9110, 15.5.12
|
||||
StatusLengthRequired status = 411 // Length Required
|
||||
// RFC 9110, 15.5.13
|
||||
StatusPreconditionFailed status = 412 // Precondition Failed
|
||||
// RFC 9110, 15.5.14
|
||||
StatusRequestEntityTooLarge status = 413 // Request Entity Too Large
|
||||
// RFC 9110, 15.5.15
|
||||
StatusRequestURITooLong status = 414 // Request URI Too Long
|
||||
// RFC 9110, 15.5.16
|
||||
StatusUnsupportedMediaType status = 415 // Unsupported Media Type
|
||||
// RFC 9110, 15.5.17
|
||||
StatusRequestedRangeNotSatisfiable status = 416 // Requested Range Not Satisfiable
|
||||
// RFC 9110, 15.5.18
|
||||
StatusExpectationFailed status = 417 // Expectation Failed
|
||||
// RFC 9110, 15.5.19 (Unused)
|
||||
StatusTeapot status = 418 // I'm a teapot
|
||||
// RFC 9110, 15.5.20
|
||||
StatusMisdirectedRequest status = 421 // Misdirected Request
|
||||
// RFC 9110, 15.5.21
|
||||
StatusUnprocessableEntity status = 422 // Unprocessable Entity
|
||||
// RFC 4918, 11.3
|
||||
StatusLocked status = 423 // Locked
|
||||
// RFC 4918, 11.4
|
||||
StatusFailedDependency status = 424 // Failed Dependency
|
||||
// RFC 8470, 5.2.
|
||||
StatusTooEarly status = 425 // Too Early
|
||||
// RFC 9110, 15.5.22
|
||||
StatusUpgradeRequired status = 426 // Upgrade Required
|
||||
// RFC 6585, 3
|
||||
StatusPreconditionRequired status = 428 // Precondition Required
|
||||
// RFC 6585, 4
|
||||
StatusTooManyRequests status = 429 // Too Many Requests
|
||||
// RFC 6585, 5
|
||||
StatusRequestHeaderFieldsTooLarge status = 431 // Request Header Fields Too Large
|
||||
// RFC 7725, 3
|
||||
StatusUnavailableForLegalReasons status = 451 // Unavailable For Legal Reasons
|
||||
|
||||
// RFC 9110, 15.6.1
|
||||
StatusInternalServerError status = 500 // Internal Server Error
|
||||
// RFC 9110, 15.6.2
|
||||
StatusNotImplemented status = 501 // Not Implemented
|
||||
// RFC 9110, 15.6.3
|
||||
StatusBadGateway status = 502 // Bad Gateway
|
||||
// RFC 9110, 15.6.4
|
||||
StatusServiceUnavailable status = 503 // Service Unavailable
|
||||
// RFC 9110, 15.6.5
|
||||
StatusGatewayTimeout status = 504 // Gateway Timeout
|
||||
// RFC 9110, 15.6.6
|
||||
StatusHTTPVersionNotSupported status = 505 // HTTP Version Not Supported
|
||||
// RFC 2295, 8.1
|
||||
StatusVariantAlsoNegotiates status = 506 // Variant Also Negotiates
|
||||
// RFC 4918, 11.5
|
||||
StatusInsufficientStorage status = 507 // Insufficient Storage
|
||||
// RFC 5842, 7.2
|
||||
StatusLoopDetected status = 508 // Loop Detected
|
||||
// RFC 2774, 7
|
||||
StatusNotExtended status = 510 // Not Extended
|
||||
// RFC 6585, 6
|
||||
StatusNetworkAuthenticationRequired status = 511 // Network Authentication Required
|
||||
)
|
||||
Reference in New Issue
Block a user