From 4dc81c32851eee068c19cb31e5620bf950a7186a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johnny=20Miller=20=28=E9=94=BA=E4=BF=8A=29?= Date: Sat, 9 May 2020 11:15:54 +0800 Subject: [PATCH] feat($HTTPStatus): add more HTTP statuses --- .../common/constant/HttpStatus.java | 155 ++++++++++++++++-- 1 file changed, 143 insertions(+), 12 deletions(-) diff --git a/common/src/main/java/com/jmsoftware/common/constant/HttpStatus.java b/common/src/main/java/com/jmsoftware/common/constant/HttpStatus.java index f9f149dc..6f58534c 100644 --- a/common/src/main/java/com/jmsoftware/common/constant/HttpStatus.java +++ b/common/src/main/java/com/jmsoftware/common/constant/HttpStatus.java @@ -12,18 +12,99 @@ * @date 2019-03-23 16:48 * @see HTTP Status Code Registry * @see List of HTTP status codes - **/ + */ @Getter @ToString @SuppressWarnings("unused") public enum HttpStatus implements IUniversalStatus { - // 2xx Success + /* + Value Description Reference + 100 Continue [RFC7231, Section 6.2.1] + 101 Switching Protocols [RFC7231, Section 6.2.2] + 102 Processing [RFC2518] + 103 Early Hints [RFC8297] + 104-199 Unassigned + 200 OK [RFC7231, Section 6.3.1] + 201 Created [RFC7231, Section 6.3.2] + 202 Accepted [RFC7231, Section 6.3.3] + 203 Non-Authoritative Information [RFC7231, Section 6.3.4] + 204 No Content [RFC7231, Section 6.3.5] + 205 Reset Content [RFC7231, Section 6.3.6] + 206 Partial Content [RFC7233, Section 4.1] + 207 Multi-Status [RFC4918] + 208 Already Reported [RFC5842] + 209-225 Unassigned + 226 IM Used [RFC3229] + 227-299 Unassigned + 300 Multiple Choices [RFC7231, Section 6.4.1] + 301 Moved Permanently [RFC7231, Section 6.4.2] + 302 Found [RFC7231, Section 6.4.3] + 303 See Other [RFC7231, Section 6.4.4] + 304 Not Modified [RFC7232, Section 4.1] + 305 Use Proxy [RFC7231, Section 6.4.5] + 306 (Unused) [RFC7231, Section 6.4.6] + 307 Temporary Redirect [RFC7231, Section 6.4.7] + 308 Permanent Redirect [RFC7538] + 309-399 Unassigned + 400 Bad Request [RFC7231, Section 6.5.1] + 401 Unauthorized [RFC7235, Section 3.1] + 402 Payment Required [RFC7231, Section 6.5.2] + 403 Forbidden [RFC7231, Section 6.5.3] + 404 Not Found [RFC7231, Section 6.5.4] + 405 Method Not Allowed [RFC7231, Section 6.5.5] + 406 Not Acceptable [RFC7231, Section 6.5.6] + 407 Proxy Authentication Required [RFC7235, Section 3.2] + 408 Request Timeout [RFC7231, Section 6.5.7] + 409 Conflict [RFC7231, Section 6.5.8] + 410 Gone [RFC7231, Section 6.5.9] + 411 Length Required [RFC7231, Section 6.5.10] + 412 Precondition Failed [RFC7232, Section 4.2][RFC8144, Section 3.2] + 413 Payload Too Large [RFC7231, Section 6.5.11] + 414 URI Too Long [RFC7231, Section 6.5.12] + 415 Unsupported Media Type [RFC7231, Section 6.5.13][RFC7694, Section 3] + 416 Range Not Satisfiable [RFC7233, Section 4.4] + 417 Expectation Failed [RFC7231, Section 6.5.14] + 418-420 Unassigned + 421 Misdirected Request [RFC7540, Section 9.1.2] + 422 Unprocessable Entity [RFC4918] + 423 Locked [RFC4918] + 424 Failed Dependency [RFC4918] + 425 Too Early [RFC8470] + 426 Upgrade Required [RFC7231, Section 6.5.15] + 427 Unassigned + 428 Precondition Required [RFC6585] + 429 Too Many Requests [RFC6585] + 430 Unassigned + 431 Request Header Fields Too Large [RFC6585] + 432-450 Unassigned + 451 Unavailable For Legal Reasons [RFC7725] + 452-499 Unassigned + 500 Internal Server Error [RFC7231, Section 6.6.1] + 501 Not Implemented [RFC7231, Section 6.6.2] + 502 Bad Gateway [RFC7231, Section 6.6.3] + 503 Service Unavailable [RFC7231, Section 6.6.4] + 504 Gateway Timeout [RFC7231, Section 6.6.5] + 505 HTTP Version Not Supported [RFC7231, Section 6.6.6] + 506 Variant Also Negotiates [RFC2295] + 507 Insufficient Storage [RFC4918] + 508 Loop Detected [RFC5842] + 509 Unassigned + 510 Not Extended [RFC2774] + 511 Network Authentication Required [RFC6585] + 512-599 Unassigned + */ + + // --- 2xx Success --- /** * Success */ OK(200, "OK. The standard response for successful HTTP requests."), // --- 4xx Client Error --- + /** + * Bad request + */ + BAD_REQUEST(400, "Bad request. The server cannot or will not process the request due to an apparent client error."), /** * Unauthorized */ @@ -42,9 +123,10 @@ public enum HttpStatus implements IUniversalStatus { */ METHOD_NOT_ALLOWED(405, "The resource was requested using a method that is not allowed."), /** - * Bad request + * Not acceptable */ - BAD_REQUEST(400, "Bad request."), + NOT_ACCEPTABLE(406, "Not Acceptable. The requested resource is capable of generating only content not acceptable " + + "according to the Accept headers sent in the request."), /** * Param not matched */ @@ -75,7 +157,27 @@ public enum HttpStatus implements IUniversalStatus { /** * Error or failure */ - ERROR(500, "Error. A generic status for an error in the server itself."), + ERROR(500, "Internal server error. A generic status for an error in the server itself."), + /** + * Not implemented + */ + NOT_IMPLEMENTED(501, "Not implemented. The server either does not recognize the request method, or it lacks the " + + "ability to fulfil the request."), + /** + * Bad gateway + */ + BAD_GATEWAY(502, "Bad gateway. The server was acting as a gateway or proxy and received an invalid response from " + + "the upstream server."), + /** + * Service unavailable + */ + SERVICE_UNAVAILABLE(503, "Service unavailable. The server cannot handle the request (because it is overloaded or " + + "down for maintenance). Generally, this is a temporary state."), + /** + * Gateway timeout + */ + GATEWAY_TIMEOUT(504, "Gateway timeout. The server was acting as a gateway or proxy and did not receive a timely " + + "response from the upstream server."), /** * Role not found */ @@ -111,11 +213,23 @@ public enum HttpStatus implements IUniversalStatus { */ private final String message; + /** + * Instantiates a new Http status. + * + * @param code the code + * @param message the message + */ HttpStatus(Integer code, String message) { this.code = code; this.message = message; } + /** + * From code http status. + * + * @param code the code + * @return the http status + */ public static HttpStatus fromCode(Integer code) { HttpStatus[] httpStatuses = HttpStatus.values(); for (HttpStatus httpStatus : httpStatuses) { @@ -129,6 +243,7 @@ public static HttpStatus fromCode(Integer code) { /** * Return the HTTP status series of this status code. * + * @return the series * @see HttpStatus.Series */ public Series series() { @@ -139,7 +254,8 @@ public Series series() { * Whether this status code is in the HTTP series {@link org.springframework.http.HttpStatus.Series#INFORMATIONAL}. * This is a shortcut for checking the value of {@link #series()}. * - * @see #series() + * @return the boolean + * @see #series() #series() */ public boolean is1xxInformational() { return (series() == Series.INFORMATIONAL); @@ -149,7 +265,8 @@ public boolean is1xxInformational() { * Whether this status code is in the HTTP series {@link org.springframework.http.HttpStatus.Series#SUCCESSFUL}. * This is a shortcut for checking the value of {@link #series()}. * - * @see #series() + * @return the boolean + * @see #series() #series() */ public boolean is2xxSuccessful() { return (series() == Series.SUCCESSFUL); @@ -159,7 +276,8 @@ public boolean is2xxSuccessful() { * Whether this status code is in the HTTP series {@link org.springframework.http.HttpStatus.Series#REDIRECTION}. * This is a shortcut for checking the value of {@link #series()}. * - * @see #series() + * @return the boolean + * @see #series() #series() */ public boolean is3xxRedirection() { return (series() == Series.REDIRECTION); @@ -169,7 +287,8 @@ public boolean is3xxRedirection() { * Whether this status code is in the HTTP series {@link org.springframework.http.HttpStatus.Series#CLIENT_ERROR}. * This is a shortcut for checking the value of {@link #series()}. * - * @see #series() + * @return the boolean + * @see #series() #series() */ public boolean is4xxClientError() { return (series() == Series.CLIENT_ERROR); @@ -179,7 +298,8 @@ public boolean is4xxClientError() { * Whether this status code is in the HTTP series {@link org.springframework.http.HttpStatus.Series#SERVER_ERROR}. * This is a shortcut for checking the value of {@link #series()}. * - * @see #series() + * @return the boolean + * @see #series() #series() */ public boolean is5xxServerError() { return (series() == Series.SERVER_ERROR); @@ -190,8 +310,9 @@ public boolean is5xxServerError() { * {@link org.springframework.http.HttpStatus.Series#SERVER_ERROR}. This is a shortcut for checking the value of * {@link #series()}. * - * @see #is4xxClientError() - * @see #is5xxServerError() + * @return the boolean + * @see #is4xxClientError() #is4xxClientError() + * @see #is5xxServerError() #is5xxServerError() * @since 5.0 */ public boolean isError() { @@ -224,14 +345,24 @@ public enum Series { */ SERVER_ERROR(5); + /** + * The Value. + */ private final int value; + /** + * Instantiates a new Series. + * + * @param value the value + */ Series(int value) { this.value = value; } /** * Return the integer value of this status series. Ranges from 1 to 5. + * + * @return the int */ public int value() { return this.value;