1// Copyright 2009 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package http
6
7// HTTP status codes as registered with IANA.
8// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
9const (
10	StatusContinue           = 100 // RFC 9110, 15.2.1
11	StatusSwitchingProtocols = 101 // RFC 9110, 15.2.2
12	StatusProcessing         = 102 // RFC 2518, 10.1
13	StatusEarlyHints         = 103 // RFC 8297
14
15	StatusOK                   = 200 // RFC 9110, 15.3.1
16	StatusCreated              = 201 // RFC 9110, 15.3.2
17	StatusAccepted             = 202 // RFC 9110, 15.3.3
18	StatusNonAuthoritativeInfo = 203 // RFC 9110, 15.3.4
19	StatusNoContent            = 204 // RFC 9110, 15.3.5
20	StatusResetContent         = 205 // RFC 9110, 15.3.6
21	StatusPartialContent       = 206 // RFC 9110, 15.3.7
22	StatusMultiStatus          = 207 // RFC 4918, 11.1
23	StatusAlreadyReported      = 208 // RFC 5842, 7.1
24	StatusIMUsed               = 226 // RFC 3229, 10.4.1
25
26	StatusMultipleChoices   = 300 // RFC 9110, 15.4.1
27	StatusMovedPermanently  = 301 // RFC 9110, 15.4.2
28	StatusFound             = 302 // RFC 9110, 15.4.3
29	StatusSeeOther          = 303 // RFC 9110, 15.4.4
30	StatusNotModified       = 304 // RFC 9110, 15.4.5
31	StatusUseProxy          = 305 // RFC 9110, 15.4.6
32	_                       = 306 // RFC 9110, 15.4.7 (Unused)
33	StatusTemporaryRedirect = 307 // RFC 9110, 15.4.8
34	StatusPermanentRedirect = 308 // RFC 9110, 15.4.9
35
36	StatusBadRequest                   = 400 // RFC 9110, 15.5.1
37	StatusUnauthorized                 = 401 // RFC 9110, 15.5.2
38	StatusPaymentRequired              = 402 // RFC 9110, 15.5.3
39	StatusForbidden                    = 403 // RFC 9110, 15.5.4
40	StatusNotFound                     = 404 // RFC 9110, 15.5.5
41	StatusMethodNotAllowed             = 405 // RFC 9110, 15.5.6
42	StatusNotAcceptable                = 406 // RFC 9110, 15.5.7
43	StatusProxyAuthRequired            = 407 // RFC 9110, 15.5.8
44	StatusRequestTimeout               = 408 // RFC 9110, 15.5.9
45	StatusConflict                     = 409 // RFC 9110, 15.5.10
46	StatusGone                         = 410 // RFC 9110, 15.5.11
47	StatusLengthRequired               = 411 // RFC 9110, 15.5.12
48	StatusPreconditionFailed           = 412 // RFC 9110, 15.5.13
49	StatusRequestEntityTooLarge        = 413 // RFC 9110, 15.5.14
50	StatusRequestURITooLong            = 414 // RFC 9110, 15.5.15
51	StatusUnsupportedMediaType         = 415 // RFC 9110, 15.5.16
52	StatusRequestedRangeNotSatisfiable = 416 // RFC 9110, 15.5.17
53	StatusExpectationFailed            = 417 // RFC 9110, 15.5.18
54	StatusTeapot                       = 418 // RFC 9110, 15.5.19 (Unused)
55	StatusMisdirectedRequest           = 421 // RFC 9110, 15.5.20
56	StatusUnprocessableEntity          = 422 // RFC 9110, 15.5.21
57	StatusLocked                       = 423 // RFC 4918, 11.3
58	StatusFailedDependency             = 424 // RFC 4918, 11.4
59	StatusTooEarly                     = 425 // RFC 8470, 5.2.
60	StatusUpgradeRequired              = 426 // RFC 9110, 15.5.22
61	StatusPreconditionRequired         = 428 // RFC 6585, 3
62	StatusTooManyRequests              = 429 // RFC 6585, 4
63	StatusRequestHeaderFieldsTooLarge  = 431 // RFC 6585, 5
64	StatusUnavailableForLegalReasons   = 451 // RFC 7725, 3
65
66	StatusInternalServerError           = 500 // RFC 9110, 15.6.1
67	StatusNotImplemented                = 501 // RFC 9110, 15.6.2
68	StatusBadGateway                    = 502 // RFC 9110, 15.6.3
69	StatusServiceUnavailable            = 503 // RFC 9110, 15.6.4
70	StatusGatewayTimeout                = 504 // RFC 9110, 15.6.5
71	StatusHTTPVersionNotSupported       = 505 // RFC 9110, 15.6.6
72	StatusVariantAlsoNegotiates         = 506 // RFC 2295, 8.1
73	StatusInsufficientStorage           = 507 // RFC 4918, 11.5
74	StatusLoopDetected                  = 508 // RFC 5842, 7.2
75	StatusNotExtended                   = 510 // RFC 2774, 7
76	StatusNetworkAuthenticationRequired = 511 // RFC 6585, 6
77)
78
79// StatusText returns a text for the HTTP status code. It returns the empty
80// string if the code is unknown.
81func StatusText(code int) string {
82	switch code {
83	case StatusContinue:
84		return "Continue"
85	case StatusSwitchingProtocols:
86		return "Switching Protocols"
87	case StatusProcessing:
88		return "Processing"
89	case StatusEarlyHints:
90		return "Early Hints"
91	case StatusOK:
92		return "OK"
93	case StatusCreated:
94		return "Created"
95	case StatusAccepted:
96		return "Accepted"
97	case StatusNonAuthoritativeInfo:
98		return "Non-Authoritative Information"
99	case StatusNoContent:
100		return "No Content"
101	case StatusResetContent:
102		return "Reset Content"
103	case StatusPartialContent:
104		return "Partial Content"
105	case StatusMultiStatus:
106		return "Multi-Status"
107	case StatusAlreadyReported:
108		return "Already Reported"
109	case StatusIMUsed:
110		return "IM Used"
111	case StatusMultipleChoices:
112		return "Multiple Choices"
113	case StatusMovedPermanently:
114		return "Moved Permanently"
115	case StatusFound:
116		return "Found"
117	case StatusSeeOther:
118		return "See Other"
119	case StatusNotModified:
120		return "Not Modified"
121	case StatusUseProxy:
122		return "Use Proxy"
123	case StatusTemporaryRedirect:
124		return "Temporary Redirect"
125	case StatusPermanentRedirect:
126		return "Permanent Redirect"
127	case StatusBadRequest:
128		return "Bad Request"
129	case StatusUnauthorized:
130		return "Unauthorized"
131	case StatusPaymentRequired:
132		return "Payment Required"
133	case StatusForbidden:
134		return "Forbidden"
135	case StatusNotFound:
136		return "Not Found"
137	case StatusMethodNotAllowed:
138		return "Method Not Allowed"
139	case StatusNotAcceptable:
140		return "Not Acceptable"
141	case StatusProxyAuthRequired:
142		return "Proxy Authentication Required"
143	case StatusRequestTimeout:
144		return "Request Timeout"
145	case StatusConflict:
146		return "Conflict"
147	case StatusGone:
148		return "Gone"
149	case StatusLengthRequired:
150		return "Length Required"
151	case StatusPreconditionFailed:
152		return "Precondition Failed"
153	case StatusRequestEntityTooLarge:
154		return "Request Entity Too Large"
155	case StatusRequestURITooLong:
156		return "Request URI Too Long"
157	case StatusUnsupportedMediaType:
158		return "Unsupported Media Type"
159	case StatusRequestedRangeNotSatisfiable:
160		return "Requested Range Not Satisfiable"
161	case StatusExpectationFailed:
162		return "Expectation Failed"
163	case StatusTeapot:
164		return "I'm a teapot"
165	case StatusMisdirectedRequest:
166		return "Misdirected Request"
167	case StatusUnprocessableEntity:
168		return "Unprocessable Entity"
169	case StatusLocked:
170		return "Locked"
171	case StatusFailedDependency:
172		return "Failed Dependency"
173	case StatusTooEarly:
174		return "Too Early"
175	case StatusUpgradeRequired:
176		return "Upgrade Required"
177	case StatusPreconditionRequired:
178		return "Precondition Required"
179	case StatusTooManyRequests:
180		return "Too Many Requests"
181	case StatusRequestHeaderFieldsTooLarge:
182		return "Request Header Fields Too Large"
183	case StatusUnavailableForLegalReasons:
184		return "Unavailable For Legal Reasons"
185	case StatusInternalServerError:
186		return "Internal Server Error"
187	case StatusNotImplemented:
188		return "Not Implemented"
189	case StatusBadGateway:
190		return "Bad Gateway"
191	case StatusServiceUnavailable:
192		return "Service Unavailable"
193	case StatusGatewayTimeout:
194		return "Gateway Timeout"
195	case StatusHTTPVersionNotSupported:
196		return "HTTP Version Not Supported"
197	case StatusVariantAlsoNegotiates:
198		return "Variant Also Negotiates"
199	case StatusInsufficientStorage:
200		return "Insufficient Storage"
201	case StatusLoopDetected:
202		return "Loop Detected"
203	case StatusNotExtended:
204		return "Not Extended"
205	case StatusNetworkAuthenticationRequired:
206		return "Network Authentication Required"
207	default:
208		return ""
209	}
210}
211