001/*
002 * Copyright 2002-2019 the original author or authors.
003 *
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 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
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 */
016
017package org.springframework.http;
018
019import org.springframework.lang.Nullable;
020
021/**
022 * Enumeration of HTTP status codes.
023 *
024 * <p>The HTTP status code series can be retrieved via {@link #series()}.
025 *
026 * @author Arjen Poutsma
027 * @author Sebastien Deleuze
028 * @author Brian Clozel
029 * @since 3.0
030 * @see HttpStatus.Series
031 * @see <a href="https://www.iana.org/assignments/http-status-codes">HTTP Status Code Registry</a>
032 * @see <a href="https://en.wikipedia.org/wiki/List_of_HTTP_status_codes">List of HTTP status codes - Wikipedia</a>
033 */
034public enum HttpStatus {
035
036        // 1xx Informational
037
038        /**
039         * {@code 100 Continue}.
040         * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.2.1">HTTP/1.1: Semantics and Content, section 6.2.1</a>
041         */
042        CONTINUE(100, "Continue"),
043        /**
044         * {@code 101 Switching Protocols}.
045         * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.2.2">HTTP/1.1: Semantics and Content, section 6.2.2</a>
046         */
047        SWITCHING_PROTOCOLS(101, "Switching Protocols"),
048        /**
049         * {@code 102 Processing}.
050         * @see <a href="https://tools.ietf.org/html/rfc2518#section-10.1">WebDAV</a>
051         */
052        PROCESSING(102, "Processing"),
053        /**
054         * {@code 103 Checkpoint}.
055         * @see <a href="https://code.google.com/p/gears/wiki/ResumableHttpRequestsProposal">A proposal for supporting
056         * resumable POST/PUT HTTP requests in HTTP/1.0</a>
057         */
058        CHECKPOINT(103, "Checkpoint"),
059
060        // 2xx Success
061
062        /**
063         * {@code 200 OK}.
064         * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.3.1">HTTP/1.1: Semantics and Content, section 6.3.1</a>
065         */
066        OK(200, "OK"),
067        /**
068         * {@code 201 Created}.
069         * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.3.2">HTTP/1.1: Semantics and Content, section 6.3.2</a>
070         */
071        CREATED(201, "Created"),
072        /**
073         * {@code 202 Accepted}.
074         * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.3.3">HTTP/1.1: Semantics and Content, section 6.3.3</a>
075         */
076        ACCEPTED(202, "Accepted"),
077        /**
078         * {@code 203 Non-Authoritative Information}.
079         * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.3.4">HTTP/1.1: Semantics and Content, section 6.3.4</a>
080         */
081        NON_AUTHORITATIVE_INFORMATION(203, "Non-Authoritative Information"),
082        /**
083         * {@code 204 No Content}.
084         * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.3.5">HTTP/1.1: Semantics and Content, section 6.3.5</a>
085         */
086        NO_CONTENT(204, "No Content"),
087        /**
088         * {@code 205 Reset Content}.
089         * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.3.6">HTTP/1.1: Semantics and Content, section 6.3.6</a>
090         */
091        RESET_CONTENT(205, "Reset Content"),
092        /**
093         * {@code 206 Partial Content}.
094         * @see <a href="https://tools.ietf.org/html/rfc7233#section-4.1">HTTP/1.1: Range Requests, section 4.1</a>
095         */
096        PARTIAL_CONTENT(206, "Partial Content"),
097        /**
098         * {@code 207 Multi-Status}.
099         * @see <a href="https://tools.ietf.org/html/rfc4918#section-13">WebDAV</a>
100         */
101        MULTI_STATUS(207, "Multi-Status"),
102        /**
103         * {@code 208 Already Reported}.
104         * @see <a href="https://tools.ietf.org/html/rfc5842#section-7.1">WebDAV Binding Extensions</a>
105         */
106        ALREADY_REPORTED(208, "Already Reported"),
107        /**
108         * {@code 226 IM Used}.
109         * @see <a href="https://tools.ietf.org/html/rfc3229#section-10.4.1">Delta encoding in HTTP</a>
110         */
111        IM_USED(226, "IM Used"),
112
113        // 3xx Redirection
114
115        /**
116         * {@code 300 Multiple Choices}.
117         * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.4.1">HTTP/1.1: Semantics and Content, section 6.4.1</a>
118         */
119        MULTIPLE_CHOICES(300, "Multiple Choices"),
120        /**
121         * {@code 301 Moved Permanently}.
122         * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.4.2">HTTP/1.1: Semantics and Content, section 6.4.2</a>
123         */
124        MOVED_PERMANENTLY(301, "Moved Permanently"),
125        /**
126         * {@code 302 Found}.
127         * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.4.3">HTTP/1.1: Semantics and Content, section 6.4.3</a>
128         */
129        FOUND(302, "Found"),
130        /**
131         * {@code 302 Moved Temporarily}.
132         * @see <a href="https://tools.ietf.org/html/rfc1945#section-9.3">HTTP/1.0, section 9.3</a>
133         * @deprecated in favor of {@link #FOUND} which will be returned from {@code HttpStatus.valueOf(302)}
134         */
135        @Deprecated
136        MOVED_TEMPORARILY(302, "Moved Temporarily"),
137        /**
138         * {@code 303 See Other}.
139         * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.4.4">HTTP/1.1: Semantics and Content, section 6.4.4</a>
140         */
141        SEE_OTHER(303, "See Other"),
142        /**
143         * {@code 304 Not Modified}.
144         * @see <a href="https://tools.ietf.org/html/rfc7232#section-4.1">HTTP/1.1: Conditional Requests, section 4.1</a>
145         */
146        NOT_MODIFIED(304, "Not Modified"),
147        /**
148         * {@code 305 Use Proxy}.
149         * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.4.5">HTTP/1.1: Semantics and Content, section 6.4.5</a>
150         * @deprecated due to security concerns regarding in-band configuration of a proxy
151         */
152        @Deprecated
153        USE_PROXY(305, "Use Proxy"),
154        /**
155         * {@code 307 Temporary Redirect}.
156         * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.4.7">HTTP/1.1: Semantics and Content, section 6.4.7</a>
157         */
158        TEMPORARY_REDIRECT(307, "Temporary Redirect"),
159        /**
160         * {@code 308 Permanent Redirect}.
161         * @see <a href="https://tools.ietf.org/html/rfc7238">RFC 7238</a>
162         */
163        PERMANENT_REDIRECT(308, "Permanent Redirect"),
164
165        // --- 4xx Client Error ---
166
167        /**
168         * {@code 400 Bad Request}.
169         * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.5.1">HTTP/1.1: Semantics and Content, section 6.5.1</a>
170         */
171        BAD_REQUEST(400, "Bad Request"),
172        /**
173         * {@code 401 Unauthorized}.
174         * @see <a href="https://tools.ietf.org/html/rfc7235#section-3.1">HTTP/1.1: Authentication, section 3.1</a>
175         */
176        UNAUTHORIZED(401, "Unauthorized"),
177        /**
178         * {@code 402 Payment Required}.
179         * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.5.2">HTTP/1.1: Semantics and Content, section 6.5.2</a>
180         */
181        PAYMENT_REQUIRED(402, "Payment Required"),
182        /**
183         * {@code 403 Forbidden}.
184         * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.5.3">HTTP/1.1: Semantics and Content, section 6.5.3</a>
185         */
186        FORBIDDEN(403, "Forbidden"),
187        /**
188         * {@code 404 Not Found}.
189         * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.5.4">HTTP/1.1: Semantics and Content, section 6.5.4</a>
190         */
191        NOT_FOUND(404, "Not Found"),
192        /**
193         * {@code 405 Method Not Allowed}.
194         * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.5.5">HTTP/1.1: Semantics and Content, section 6.5.5</a>
195         */
196        METHOD_NOT_ALLOWED(405, "Method Not Allowed"),
197        /**
198         * {@code 406 Not Acceptable}.
199         * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.5.6">HTTP/1.1: Semantics and Content, section 6.5.6</a>
200         */
201        NOT_ACCEPTABLE(406, "Not Acceptable"),
202        /**
203         * {@code 407 Proxy Authentication Required}.
204         * @see <a href="https://tools.ietf.org/html/rfc7235#section-3.2">HTTP/1.1: Authentication, section 3.2</a>
205         */
206        PROXY_AUTHENTICATION_REQUIRED(407, "Proxy Authentication Required"),
207        /**
208         * {@code 408 Request Timeout}.
209         * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.5.7">HTTP/1.1: Semantics and Content, section 6.5.7</a>
210         */
211        REQUEST_TIMEOUT(408, "Request Timeout"),
212        /**
213         * {@code 409 Conflict}.
214         * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.5.8">HTTP/1.1: Semantics and Content, section 6.5.8</a>
215         */
216        CONFLICT(409, "Conflict"),
217        /**
218         * {@code 410 Gone}.
219         * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.5.9">
220         *     HTTP/1.1: Semantics and Content, section 6.5.9</a>
221         */
222        GONE(410, "Gone"),
223        /**
224         * {@code 411 Length Required}.
225         * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.5.10">
226         *     HTTP/1.1: Semantics and Content, section 6.5.10</a>
227         */
228        LENGTH_REQUIRED(411, "Length Required"),
229        /**
230         * {@code 412 Precondition failed}.
231         * @see <a href="https://tools.ietf.org/html/rfc7232#section-4.2">
232         *     HTTP/1.1: Conditional Requests, section 4.2</a>
233         */
234        PRECONDITION_FAILED(412, "Precondition Failed"),
235        /**
236         * {@code 413 Payload Too Large}.
237         * @since 4.1
238         * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.5.11">
239         *     HTTP/1.1: Semantics and Content, section 6.5.11</a>
240         */
241        PAYLOAD_TOO_LARGE(413, "Payload Too Large"),
242        /**
243         * {@code 413 Request Entity Too Large}.
244         * @see <a href="https://tools.ietf.org/html/rfc2616#section-10.4.14">HTTP/1.1, section 10.4.14</a>
245         * @deprecated in favor of {@link #PAYLOAD_TOO_LARGE} which will be
246         * returned from {@code HttpStatus.valueOf(413)}
247         */
248        @Deprecated
249        REQUEST_ENTITY_TOO_LARGE(413, "Request Entity Too Large"),
250        /**
251         * {@code 414 URI Too Long}.
252         * @since 4.1
253         * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.5.12">
254         *     HTTP/1.1: Semantics and Content, section 6.5.12</a>
255         */
256        URI_TOO_LONG(414, "URI Too Long"),
257        /**
258         * {@code 414 Request-URI Too Long}.
259         * @see <a href="https://tools.ietf.org/html/rfc2616#section-10.4.15">HTTP/1.1, section 10.4.15</a>
260         * @deprecated in favor of {@link #URI_TOO_LONG} which will be returned from {@code HttpStatus.valueOf(414)}
261         */
262        @Deprecated
263        REQUEST_URI_TOO_LONG(414, "Request-URI Too Long"),
264        /**
265         * {@code 415 Unsupported Media Type}.
266         * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.5.13">
267         *     HTTP/1.1: Semantics and Content, section 6.5.13</a>
268         */
269        UNSUPPORTED_MEDIA_TYPE(415, "Unsupported Media Type"),
270        /**
271         * {@code 416 Requested Range Not Satisfiable}.
272         * @see <a href="https://tools.ietf.org/html/rfc7233#section-4.4">HTTP/1.1: Range Requests, section 4.4</a>
273         */
274        REQUESTED_RANGE_NOT_SATISFIABLE(416, "Requested range not satisfiable"),
275        /**
276         * {@code 417 Expectation Failed}.
277         * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.5.14">
278         *     HTTP/1.1: Semantics and Content, section 6.5.14</a>
279         */
280        EXPECTATION_FAILED(417, "Expectation Failed"),
281        /**
282         * {@code 418 I'm a teapot}.
283         * @see <a href="https://tools.ietf.org/html/rfc2324#section-2.3.2">HTCPCP/1.0</a>
284         */
285        I_AM_A_TEAPOT(418, "I'm a teapot"),
286        /**
287         * @deprecated See
288         * <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        INSUFFICIENT_SPACE_ON_RESOURCE(419, "Insufficient Space On Resource"),
293        /**
294         * @deprecated See
295         * <a href="https://tools.ietf.org/rfcdiff?difftype=--hwdiff&url2=draft-ietf-webdav-protocol-06.txt">
296         *     WebDAV Draft Changes</a>
297         */
298        @Deprecated
299        METHOD_FAILURE(420, "Method Failure"),
300        /**
301         * @deprecated
302         * See <a href="https://tools.ietf.org/rfcdiff?difftype=--hwdiff&url2=draft-ietf-webdav-protocol-06.txt">
303         *     WebDAV Draft Changes</a>
304         */
305        @Deprecated
306        DESTINATION_LOCKED(421, "Destination Locked"),
307        /**
308         * {@code 422 Unprocessable Entity}.
309         * @see <a href="https://tools.ietf.org/html/rfc4918#section-11.2">WebDAV</a>
310         */
311        UNPROCESSABLE_ENTITY(422, "Unprocessable Entity"),
312        /**
313         * {@code 423 Locked}.
314         * @see <a href="https://tools.ietf.org/html/rfc4918#section-11.3">WebDAV</a>
315         */
316        LOCKED(423, "Locked"),
317        /**
318         * {@code 424 Failed Dependency}.
319         * @see <a href="https://tools.ietf.org/html/rfc4918#section-11.4">WebDAV</a>
320         */
321        FAILED_DEPENDENCY(424, "Failed Dependency"),
322        /**
323         * {@code 425 Too Early}.
324         * @since 5.2
325         * @see <a href="https://tools.ietf.org/html/rfc8470">RFC 8470</a>
326         */
327        TOO_EARLY(425, "Too Early"),
328        /**
329         * {@code 426 Upgrade Required}.
330         * @see <a href="https://tools.ietf.org/html/rfc2817#section-6">Upgrading to TLS Within HTTP/1.1</a>
331         */
332        UPGRADE_REQUIRED(426, "Upgrade Required"),
333        /**
334         * {@code 428 Precondition Required}.
335         * @see <a href="https://tools.ietf.org/html/rfc6585#section-3">Additional HTTP Status Codes</a>
336         */
337        PRECONDITION_REQUIRED(428, "Precondition Required"),
338        /**
339         * {@code 429 Too Many Requests}.
340         * @see <a href="https://tools.ietf.org/html/rfc6585#section-4">Additional HTTP Status Codes</a>
341         */
342        TOO_MANY_REQUESTS(429, "Too Many Requests"),
343        /**
344         * {@code 431 Request Header Fields Too Large}.
345         * @see <a href="https://tools.ietf.org/html/rfc6585#section-5">Additional HTTP Status Codes</a>
346         */
347        REQUEST_HEADER_FIELDS_TOO_LARGE(431, "Request Header Fields Too Large"),
348        /**
349         * {@code 451 Unavailable For Legal Reasons}.
350         * @see <a href="https://tools.ietf.org/html/draft-ietf-httpbis-legally-restricted-status-04">
351         * An HTTP Status Code to Report Legal Obstacles</a>
352         * @since 4.3
353         */
354        UNAVAILABLE_FOR_LEGAL_REASONS(451, "Unavailable For Legal Reasons"),
355
356        // --- 5xx Server Error ---
357
358        /**
359         * {@code 500 Internal Server Error}.
360         * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.6.1">HTTP/1.1: Semantics and Content, section 6.6.1</a>
361         */
362        INTERNAL_SERVER_ERROR(500, "Internal Server Error"),
363        /**
364         * {@code 501 Not Implemented}.
365         * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.6.2">HTTP/1.1: Semantics and Content, section 6.6.2</a>
366         */
367        NOT_IMPLEMENTED(501, "Not Implemented"),
368        /**
369         * {@code 502 Bad Gateway}.
370         * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.6.3">HTTP/1.1: Semantics and Content, section 6.6.3</a>
371         */
372        BAD_GATEWAY(502, "Bad Gateway"),
373        /**
374         * {@code 503 Service Unavailable}.
375         * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.6.4">HTTP/1.1: Semantics and Content, section 6.6.4</a>
376         */
377        SERVICE_UNAVAILABLE(503, "Service Unavailable"),
378        /**
379         * {@code 504 Gateway Timeout}.
380         * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.6.5">HTTP/1.1: Semantics and Content, section 6.6.5</a>
381         */
382        GATEWAY_TIMEOUT(504, "Gateway Timeout"),
383        /**
384         * {@code 505 HTTP Version Not Supported}.
385         * @see <a href="https://tools.ietf.org/html/rfc7231#section-6.6.6">HTTP/1.1: Semantics and Content, section 6.6.6</a>
386         */
387        HTTP_VERSION_NOT_SUPPORTED(505, "HTTP Version not supported"),
388        /**
389         * {@code 506 Variant Also Negotiates}
390         * @see <a href="https://tools.ietf.org/html/rfc2295#section-8.1">Transparent Content Negotiation</a>
391         */
392        VARIANT_ALSO_NEGOTIATES(506, "Variant Also Negotiates"),
393        /**
394         * {@code 507 Insufficient Storage}
395         * @see <a href="https://tools.ietf.org/html/rfc4918#section-11.5">WebDAV</a>
396         */
397        INSUFFICIENT_STORAGE(507, "Insufficient Storage"),
398        /**
399         * {@code 508 Loop Detected}
400         * @see <a href="https://tools.ietf.org/html/rfc5842#section-7.2">WebDAV Binding Extensions</a>
401         */
402        LOOP_DETECTED(508, "Loop Detected"),
403        /**
404         * {@code 509 Bandwidth Limit Exceeded}
405         */
406        BANDWIDTH_LIMIT_EXCEEDED(509, "Bandwidth Limit Exceeded"),
407        /**
408         * {@code 510 Not Extended}
409         * @see <a href="https://tools.ietf.org/html/rfc2774#section-7">HTTP Extension Framework</a>
410         */
411        NOT_EXTENDED(510, "Not Extended"),
412        /**
413         * {@code 511 Network Authentication Required}.
414         * @see <a href="https://tools.ietf.org/html/rfc6585#section-6">Additional HTTP Status Codes</a>
415         */
416        NETWORK_AUTHENTICATION_REQUIRED(511, "Network Authentication Required");
417
418
419        private final int value;
420
421        private final String reasonPhrase;
422
423
424        HttpStatus(int value, String reasonPhrase) {
425                this.value = value;
426                this.reasonPhrase = reasonPhrase;
427        }
428
429
430        /**
431         * Return the integer value of this status code.
432         */
433        public int value() {
434                return this.value;
435        }
436
437        /**
438         * Return the reason phrase of this status code.
439         */
440        public String getReasonPhrase() {
441                return this.reasonPhrase;
442        }
443
444        /**
445         * Return the HTTP status series of this status code.
446         * @see HttpStatus.Series
447         */
448        public Series series() {
449                return Series.valueOf(this);
450        }
451
452        /**
453         * Whether this status code is in the HTTP series
454         * {@link org.springframework.http.HttpStatus.Series#INFORMATIONAL}.
455         * This is a shortcut for checking the value of {@link #series()}.
456         * @since 4.0
457         * @see #series()
458         */
459        public boolean is1xxInformational() {
460                return (series() == Series.INFORMATIONAL);
461        }
462
463        /**
464         * Whether this status code is in the HTTP series
465         * {@link org.springframework.http.HttpStatus.Series#SUCCESSFUL}.
466         * This is a shortcut for checking the value of {@link #series()}.
467         * @since 4.0
468         * @see #series()
469         */
470        public boolean is2xxSuccessful() {
471                return (series() == Series.SUCCESSFUL);
472        }
473
474        /**
475         * Whether this status code is in the HTTP series
476         * {@link org.springframework.http.HttpStatus.Series#REDIRECTION}.
477         * This is a shortcut for checking the value of {@link #series()}.
478         * @since 4.0
479         * @see #series()
480         */
481        public boolean is3xxRedirection() {
482                return (series() == Series.REDIRECTION);
483        }
484
485        /**
486         * Whether this status code is in the HTTP series
487         * {@link org.springframework.http.HttpStatus.Series#CLIENT_ERROR}.
488         * This is a shortcut for checking the value of {@link #series()}.
489         * @since 4.0
490         * @see #series()
491         */
492        public boolean is4xxClientError() {
493                return (series() == Series.CLIENT_ERROR);
494        }
495
496        /**
497         * Whether this status code is in the HTTP series
498         * {@link org.springframework.http.HttpStatus.Series#SERVER_ERROR}.
499         * This is a shortcut for checking the value of {@link #series()}.
500         * @since 4.0
501         * @see #series()
502         */
503        public boolean is5xxServerError() {
504                return (series() == Series.SERVER_ERROR);
505        }
506
507        /**
508         * Whether this status code is in the HTTP series
509         * {@link org.springframework.http.HttpStatus.Series#CLIENT_ERROR} or
510         * {@link org.springframework.http.HttpStatus.Series#SERVER_ERROR}.
511         * This is a shortcut for checking the value of {@link #series()}.
512         * @since 5.0
513         * @see #is4xxClientError()
514         * @see #is5xxServerError()
515         */
516        public boolean isError() {
517                return (is4xxClientError() || is5xxServerError());
518        }
519
520        /**
521         * Return a string representation of this status code.
522         */
523        @Override
524        public String toString() {
525                return this.value + " " + name();
526        }
527
528
529        /**
530         * Return the enum constant of this type with the specified numeric value.
531         * @param statusCode the numeric value of the enum to be returned
532         * @return the enum constant with the specified numeric value
533         * @throws IllegalArgumentException if this enum has no constant for the specified numeric value
534         */
535        public static HttpStatus valueOf(int statusCode) {
536                HttpStatus status = resolve(statusCode);
537                if (status == null) {
538                        throw new IllegalArgumentException("No matching constant for [" + statusCode + "]");
539                }
540                return status;
541        }
542
543        /**
544         * Resolve the given status code to an {@code HttpStatus}, if possible.
545         * @param statusCode the HTTP status code (potentially non-standard)
546         * @return the corresponding {@code HttpStatus}, or {@code null} if not found
547         * @since 5.0
548         */
549        @Nullable
550        public static HttpStatus resolve(int statusCode) {
551                for (HttpStatus status : values()) {
552                        if (status.value == statusCode) {
553                                return status;
554                        }
555                }
556                return null;
557        }
558
559
560        /**
561         * Enumeration of HTTP status series.
562         * <p>Retrievable via {@link HttpStatus#series()}.
563         */
564        public enum Series {
565
566                INFORMATIONAL(1),
567                SUCCESSFUL(2),
568                REDIRECTION(3),
569                CLIENT_ERROR(4),
570                SERVER_ERROR(5);
571
572                private final int value;
573
574                Series(int value) {
575                        this.value = value;
576                }
577
578                /**
579                 * Return the integer value of this status series. Ranges from 1 to 5.
580                 */
581                public int value() {
582                        return this.value;
583                }
584
585                /**
586                 * Return the enum constant of this type with the corresponding series.
587                 * @param status a standard HTTP status enum value
588                 * @return the enum constant of this type with the corresponding series
589                 * @throws IllegalArgumentException if this enum has no corresponding constant
590                 */
591                public static Series valueOf(HttpStatus status) {
592                        return valueOf(status.value);
593                }
594
595                /**
596                 * Return the enum constant of this type with the corresponding series.
597                 * @param statusCode the HTTP status code (potentially non-standard)
598                 * @return the enum constant of this type with the corresponding series
599                 * @throws IllegalArgumentException if this enum has no corresponding constant
600                 */
601                public static Series valueOf(int statusCode) {
602                        Series series = resolve(statusCode);
603                        if (series == null) {
604                                throw new IllegalArgumentException("No matching constant for [" + statusCode + "]");
605                        }
606                        return series;
607                }
608
609                /**
610                 * Resolve the given status code to an {@code HttpStatus.Series}, if possible.
611                 * @param statusCode the HTTP status code (potentially non-standard)
612                 * @return the corresponding {@code Series}, or {@code null} if not found
613                 * @since 5.1.3
614                 */
615                @Nullable
616                public static Series resolve(int statusCode) {
617                        int seriesCode = statusCode / 100;
618                        for (Series series : values()) {
619                                if (series.value == seriesCode) {
620                                        return series;
621                                }
622                        }
623                        return null;
624                }
625        }
626
627}