001/** 002 * Copyright (c) 2015-2022, Michael Yang 杨福海 (fuhai999@gmail.com). 003 * <p> 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * <p> 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * <p> 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package io.jboot.web; 017 018/** 019 * @author michael yang (fuhai999@gmail.com) 020 * @Date: 2020/4/6 021 */ 022public enum HttpStatus { 023 024 /** 025 * {@code 100 Continue}. 026 * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.2.1">HTTP/1.1: Semantics and Content, section 6.2.1</a> 027 */ 028 CONTINUE(100, "Continue"), 029 /** 030 * {@code 101 Switching Protocols}. 031 * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.2.2">HTTP/1.1: Semantics and Content, section 6.2.2</a> 032 */ 033 SWITCHING_PROTOCOLS(101, "Switching Protocols"), 034 /** 035 * {@code 102 Processing}. 036 * @see <a href="https://tools.ietf.org/html/rfc2518#section-10.1">WebDAV</a> 037 */ 038 PROCESSING(102, "Processing"), 039 /** 040 * {@code 103 Checkpoint}. 041 * @see <a href="https://code.google.com/p/gears/wiki/ResumableHttpRequestsProposal">A proposal for supporting 042 * resumable POST/PUT HTTP requests in HTTP/1.0</a> 043 */ 044 CHECKPOINT(103, "Checkpoint"), 045 046 // 2xx Success 047 048 /** 049 * {@code 200 OK}. 050 * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.3.1">HTTP/1.1: Semantics and Content, section 6.3.1</a> 051 */ 052 OK(200, "OK"), 053 /** 054 * {@code 201 Created}. 055 * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.3.2">HTTP/1.1: Semantics and Content, section 6.3.2</a> 056 */ 057 CREATED(201, "Created"), 058 /** 059 * {@code 202 Accepted}. 060 * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.3.3">HTTP/1.1: Semantics and Content, section 6.3.3</a> 061 */ 062 ACCEPTED(202, "Accepted"), 063 /** 064 * {@code 203 Non-Authoritative Information}. 065 * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.3.4">HTTP/1.1: Semantics and Content, section 6.3.4</a> 066 */ 067 NON_AUTHORITATIVE_INFORMATION(203, "Non-Authoritative Information"), 068 /** 069 * {@code 204 No Content}. 070 * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.3.5">HTTP/1.1: Semantics and Content, section 6.3.5</a> 071 */ 072 NO_CONTENT(204, "No Content"), 073 /** 074 * {@code 205 Reset Content}. 075 * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.3.6">HTTP/1.1: Semantics and Content, section 6.3.6</a> 076 */ 077 RESET_CONTENT(205, "Reset Content"), 078 /** 079 * {@code 206 Partial Content}. 080 * @see <a href="https://tools.ietf.org/html/rfc7233#section-4.1">HTTP/1.1: Range Requests, section 4.1</a> 081 */ 082 PARTIAL_CONTENT(206, "Partial Content"), 083 /** 084 * {@code 207 Multi-Status}. 085 * @see <a href="https://tools.ietf.org/html/rfc4918#section-13">WebDAV</a> 086 */ 087 MULTI_STATUS(207, "Multi-Status"), 088 /** 089 * {@code 208 Already Reported}. 090 * @see <a href="https://tools.ietf.org/html/rfc5842#section-7.1">WebDAV Binding Extensions</a> 091 */ 092 ALREADY_REPORTED(208, "Already Reported"), 093 /** 094 * {@code 226 IM Used}. 095 * @see <a href="https://tools.ietf.org/html/rfc3229#section-10.4.1">Delta encoding in HTTP</a> 096 */ 097 IM_USED(226, "IM Used"), 098 099 // 3xx Redirection 100 101 /** 102 * {@code 300 Multiple Choices}. 103 * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.4.1">HTTP/1.1: Semantics and Content, section 6.4.1</a> 104 */ 105 MULTIPLE_CHOICES(300, "Multiple Choices"), 106 /** 107 * {@code 301 Moved Permanently}. 108 * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.4.2">HTTP/1.1: Semantics and Content, section 6.4.2</a> 109 */ 110 MOVED_PERMANENTLY(301, "Moved Permanently"), 111 /** 112 * {@code 302 Found}. 113 * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.4.3">HTTP/1.1: Semantics and Content, section 6.4.3</a> 114 */ 115 FOUND(302, "Found"), 116 /** 117 * {@code 302 Moved Temporarily}. 118 * @see <a href="https://tools.ietf.org/html/rfc1945#section-9.3">HTTP/1.0, section 9.3</a> 119 * @deprecated in favor of {@link #FOUND} which will be returned from {@code HttpStatus.valueOf(302)} 120 */ 121 @Deprecated 122 MOVED_TEMPORARILY(302, "Moved Temporarily"), 123 /** 124 * {@code 303 See Other}. 125 * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.4.4">HTTP/1.1: Semantics and Content, section 6.4.4</a> 126 */ 127 SEE_OTHER(303, "See Other"), 128 /** 129 * {@code 304 Not Modified}. 130 * @see <a href="https://tools.ietf.org/html/rfc7232#section-4.1">HTTP/1.1: Conditional Requests, section 4.1</a> 131 */ 132 NOT_MODIFIED(304, "Not Modified"), 133 /** 134 * {@code 305 Use Proxy}. 135 * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.4.5">HTTP/1.1: Semantics and Content, section 6.4.5</a> 136 * @deprecated due to security concerns regarding in-band configuration of a proxy 137 */ 138 @Deprecated 139 USE_PROXY(305, "Use Proxy"), 140 /** 141 * {@code 307 Temporary Redirect}. 142 * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.4.7">HTTP/1.1: Semantics and Content, section 6.4.7</a> 143 */ 144 TEMPORARY_REDIRECT(307, "Temporary Redirect"), 145 /** 146 * {@code 308 Permanent Redirect}. 147 * @see <a href="https://tools.ietf.org/html/rfc7238">RFC 7238</a> 148 */ 149 PERMANENT_REDIRECT(308, "Permanent Redirect"), 150 151 // --- 4xx Client Error --- 152 153 /** 154 * {@code 400 Bad Request}. 155 * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.5.1">HTTP/1.1: Semantics and Content, section 6.5.1</a> 156 */ 157 BAD_REQUEST(400, "Bad Request"), 158 /** 159 * {@code 401 Unauthorized}. 160 * @see <a href="https://tools.ietf.org/html/rfc7235#section-3.1">HTTP/1.1: Authentication, section 3.1</a> 161 */ 162 UNAUTHORIZED(401, "Unauthorized"), 163 /** 164 * {@code 402 Payment Required}. 165 * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.5.2">HTTP/1.1: Semantics and Content, section 6.5.2</a> 166 */ 167 PAYMENT_REQUIRED(402, "Payment Required"), 168 /** 169 * {@code 403 Forbidden}. 170 * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.5.3">HTTP/1.1: Semantics and Content, section 6.5.3</a> 171 */ 172 FORBIDDEN(403, "Forbidden"), 173 /** 174 * {@code 404 Not Found}. 175 * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.5.4">HTTP/1.1: Semantics and Content, section 6.5.4</a> 176 */ 177 NOT_FOUND(404, "Not Found"), 178 /** 179 * {@code 405 Method Not Allowed}. 180 * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.5.5">HTTP/1.1: Semantics and Content, section 6.5.5</a> 181 */ 182 METHOD_NOT_ALLOWED(405, "Method Not Allowed"), 183 /** 184 * {@code 406 Not Acceptable}. 185 * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.5.6">HTTP/1.1: Semantics and Content, section 6.5.6</a> 186 */ 187 NOT_ACCEPTABLE(406, "Not Acceptable"), 188 /** 189 * {@code 407 Proxy Authentication Required}. 190 * @see <a href="https://tools.ietf.org/html/rfc7235#section-3.2">HTTP/1.1: Authentication, section 3.2</a> 191 */ 192 PROXY_AUTHENTICATION_REQUIRED(407, "Proxy Authentication Required"), 193 /** 194 * {@code 408 Request Timeout}. 195 * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.5.7">HTTP/1.1: Semantics and Content, section 6.5.7</a> 196 */ 197 REQUEST_TIMEOUT(408, "Request Timeout"), 198 /** 199 * {@code 409 Conflict}. 200 * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.5.8">HTTP/1.1: Semantics and Content, section 6.5.8</a> 201 */ 202 CONFLICT(409, "Conflict"), 203 /** 204 * {@code 410 Gone}. 205 * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.5.9"> 206 * HTTP/1.1: Semantics and Content, section 6.5.9</a> 207 */ 208 GONE(410, "Gone"), 209 /** 210 * {@code 411 Length Required}. 211 * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.5.10"> 212 * HTTP/1.1: Semantics and Content, section 6.5.10</a> 213 */ 214 LENGTH_REQUIRED(411, "Length Required"), 215 /** 216 * {@code 412 Precondition failed}. 217 * @see <a href="https://tools.ietf.org/html/rfc7232#section-4.2"> 218 * HTTP/1.1: Conditional Requests, section 4.2</a> 219 */ 220 PRECONDITION_FAILED(412, "Precondition Failed"), 221 /** 222 * {@code 413 Payload Too Large}. 223 * @since 4.1 224 * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.5.11"> 225 * HTTP/1.1: Semantics and Content, section 6.5.11</a> 226 */ 227 PAYLOAD_TOO_LARGE(413, "Payload Too Large"), 228 /** 229 * {@code 413 Request Entity Too Large}. 230 * @see <a href="https://tools.ietf.org/html/rfc2616#section-10.4.14">HTTP/1.1, section 10.4.14</a> 231 * @deprecated in favor of {@link #PAYLOAD_TOO_LARGE} which will be 232 * returned from {@code HttpStatus.valueOf(413)} 233 */ 234 @Deprecated 235 REQUEST_ENTITY_TOO_LARGE(413, "Request Entity Too Large"), 236 /** 237 * {@code 414 URI Too Long}. 238 * @since 4.1 239 * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.5.12"> 240 * HTTP/1.1: Semantics and Content, section 6.5.12</a> 241 */ 242 URI_TOO_LONG(414, "URI Too Long"), 243 /** 244 * {@code 414 Request-URI Too Long}. 245 * @see <a href="https://tools.ietf.org/html/rfc2616#section-10.4.15">HTTP/1.1, section 10.4.15</a> 246 * @deprecated in favor of {@link #URI_TOO_LONG} which will be returned from {@code HttpStatus.valueOf(414)} 247 */ 248 @Deprecated 249 REQUEST_URI_TOO_LONG(414, "Request-URI Too Long"), 250 /** 251 * {@code 415 Unsupported Media Type}. 252 * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.5.13"> 253 * HTTP/1.1: Semantics and Content, section 6.5.13</a> 254 */ 255 UNSUPPORTED_MEDIA_TYPE(415, "Unsupported Media Type"), 256 /** 257 * {@code 416 Requested Range Not Satisfiable}. 258 * @see <a href="https://tools.ietf.org/html/rfc7233#section-4.4">HTTP/1.1: Range Requests, section 4.4</a> 259 */ 260 REQUESTED_RANGE_NOT_SATISFIABLE(416, "Requested range not satisfiable"), 261 /** 262 * {@code 417 Expectation Failed}. 263 * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.5.14"> 264 * HTTP/1.1: Semantics and Content, section 6.5.14</a> 265 */ 266 EXPECTATION_FAILED(417, "Expectation Failed"), 267 /** 268 * {@code 418 I'm a teapot}. 269 * @see <a href="https://tools.ietf.org/html/rfc2324#section-2.3.2">HTCPCP/1.0</a> 270 */ 271 I_AM_A_TEAPOT(418, "I'm a teapot"), 272 /** 273 * @deprecated See 274 * <a href="https://tools.ietf.org/rfcdiff?difftype=--hwdiff&url2=draft-ietf-webdav-protocol-06.txt"> 275 * WebDAV Draft Changes</a> 276 */ 277 @Deprecated 278 INSUFFICIENT_SPACE_ON_RESOURCE(419, "Insufficient Space On Resource"), 279 /** 280 * @deprecated See 281 * <a href="https://tools.ietf.org/rfcdiff?difftype=--hwdiff&url2=draft-ietf-webdav-protocol-06.txt"> 282 * WebDAV Draft Changes</a> 283 */ 284 @Deprecated 285 METHOD_FAILURE(420, "Method Failure"), 286 /** 287 * @deprecated 288 * See <a href="https://tools.ietf.org/rfcdiff?difftype=--hwdiff&url2=draft-ietf-webdav-protocol-06.txt"> 289 * WebDAV Draft Changes</a> 290 */ 291 @Deprecated 292 DESTINATION_LOCKED(421, "Destination Locked"), 293 /** 294 * {@code 422 Unprocessable Entity}. 295 * @see <a href="https://tools.ietf.org/html/rfc4918#section-11.2">WebDAV</a> 296 */ 297 UNPROCESSABLE_ENTITY(422, "Unprocessable Entity"), 298 /** 299 * {@code 423 Locked}. 300 * @see <a href="https://tools.ietf.org/html/rfc4918#section-11.3">WebDAV</a> 301 */ 302 LOCKED(423, "Locked"), 303 /** 304 * {@code 424 Failed Dependency}. 305 * @see <a href="https://tools.ietf.org/html/rfc4918#section-11.4">WebDAV</a> 306 */ 307 FAILED_DEPENDENCY(424, "Failed Dependency"), 308 /** 309 * {@code 426 Upgrade Required}. 310 * @see <a href="https://tools.ietf.org/html/rfc2817#section-6">Upgrading to TLS Within HTTP/1.1</a> 311 */ 312 UPGRADE_REQUIRED(426, "Upgrade Required"), 313 /** 314 * {@code 428 Precondition Required}. 315 * @see <a href="https://tools.ietf.org/html/rfc6585#section-3">Additional HTTP Status Codes</a> 316 */ 317 PRECONDITION_REQUIRED(428, "Precondition Required"), 318 /** 319 * {@code 429 Too Many Requests}. 320 * @see <a href="https://tools.ietf.org/html/rfc6585#section-4">Additional HTTP Status Codes</a> 321 */ 322 TOO_MANY_REQUESTS(429, "Too Many Requests"), 323 /** 324 * {@code 431 Request Header Fields Too Large}. 325 * @see <a href="https://tools.ietf.org/html/rfc6585#section-5">Additional HTTP Status Codes</a> 326 */ 327 REQUEST_HEADER_FIELDS_TOO_LARGE(431, "Request Header Fields Too Large"), 328 /** 329 * {@code 451 Unavailable For Legal Reasons}. 330 * @see <a href="https://tools.ietf.org/html/draft-ietf-httpbis-legally-restricted-status-04"> 331 * An HTTP Status Code to Report Legal Obstacles</a> 332 * @since 4.3 333 */ 334 UNAVAILABLE_FOR_LEGAL_REASONS(451, "Unavailable For Legal Reasons"), 335 336 // --- 5xx Server Error --- 337 338 /** 339 * {@code 500 Internal Server Error}. 340 * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.6.1">HTTP/1.1: Semantics and Content, section 6.6.1</a> 341 */ 342 INTERNAL_SERVER_ERROR(500, "Internal Server Error"), 343 /** 344 * {@code 501 Not Implemented}. 345 * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.6.2">HTTP/1.1: Semantics and Content, section 6.6.2</a> 346 */ 347 NOT_IMPLEMENTED(501, "Not Implemented"), 348 /** 349 * {@code 502 Bad Gateway}. 350 * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.6.3">HTTP/1.1: Semantics and Content, section 6.6.3</a> 351 */ 352 BAD_GATEWAY(502, "Bad Gateway"), 353 /** 354 * {@code 503 Service Unavailable}. 355 * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.6.4">HTTP/1.1: Semantics and Content, section 6.6.4</a> 356 */ 357 SERVICE_UNAVAILABLE(503, "Service Unavailable"), 358 /** 359 * {@code 504 Gateway Timeout}. 360 * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.6.5">HTTP/1.1: Semantics and Content, section 6.6.5</a> 361 */ 362 GATEWAY_TIMEOUT(504, "Gateway Timeout"), 363 /** 364 * {@code 505 HTTP Version Not Supported}. 365 * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.6.6">HTTP/1.1: Semantics and Content, section 6.6.6</a> 366 */ 367 HTTP_VERSION_NOT_SUPPORTED(505, "HTTP Version not supported"), 368 /** 369 * {@code 506 Variant Also Negotiates} 370 * @see <a href="https://tools.ietf.org/html/rfc2295#section-8.1">Transparent Content Negotiation</a> 371 */ 372 VARIANT_ALSO_NEGOTIATES(506, "Variant Also Negotiates"), 373 /** 374 * {@code 507 Insufficient Storage} 375 * @see <a href="https://tools.ietf.org/html/rfc4918#section-11.5">WebDAV</a> 376 */ 377 INSUFFICIENT_STORAGE(507, "Insufficient Storage"), 378 /** 379 * {@code 508 Loop Detected} 380 * @see <a href="https://tools.ietf.org/html/rfc5842#section-7.2">WebDAV Binding Extensions</a> 381 */ 382 LOOP_DETECTED(508, "Loop Detected"), 383 /** 384 * {@code 509 Bandwidth Limit Exceeded} 385 */ 386 BANDWIDTH_LIMIT_EXCEEDED(509, "Bandwidth Limit Exceeded"), 387 /** 388 * {@code 510 Not Extended} 389 * @see <a href="https://tools.ietf.org/html/rfc2774#section-7">HTTP Extension Framework</a> 390 */ 391 NOT_EXTENDED(510, "Not Extended"), 392 /** 393 * {@code 511 Network Authentication Required}. 394 * @see <a href="https://tools.ietf.org/html/rfc6585#section-6">Additional HTTP Status Codes</a> 395 */ 396 NETWORK_AUTHENTICATION_REQUIRED(511, "Network Authentication Required"); 397 398 399 private final int value; 400 401 private final String reasonPhrase; 402 403 404 HttpStatus(int value, String reasonPhrase) { 405 this.value = value; 406 this.reasonPhrase = reasonPhrase; 407 } 408 409 410 /** 411 * Return the integer value of this status code. 412 */ 413 public int value() { 414 return this.value; 415 } 416 417 /** 418 * Return the reason phrase of this status code. 419 */ 420 public String getReasonPhrase() { 421 return this.reasonPhrase; 422 } 423}