- Rename httpResponseStatus() to newStatus()
  - Move newStatus up so that static methods are grouped together
- Rename codeAsString to codeAsText
This commit is contained in:
Trustin Lee 2014-11-20 19:08:16 +09:00
parent 3ebc1ab321
commit ef11a31a06

View File

@ -31,286 +31,290 @@ public class HttpResponseStatus implements Comparable<HttpResponseStatus> {
/** /**
* 100 Continue * 100 Continue
*/ */
public static final HttpResponseStatus CONTINUE = httpResponseStatus(100, "Continue"); public static final HttpResponseStatus CONTINUE = newStatus(100, "Continue");
/** /**
* 101 Switching Protocols * 101 Switching Protocols
*/ */
public static final HttpResponseStatus SWITCHING_PROTOCOLS = httpResponseStatus(101, "Switching Protocols"); public static final HttpResponseStatus SWITCHING_PROTOCOLS = newStatus(101, "Switching Protocols");
/** /**
* 102 Processing (WebDAV, RFC2518) * 102 Processing (WebDAV, RFC2518)
*/ */
public static final HttpResponseStatus PROCESSING = httpResponseStatus(102, "Processing"); public static final HttpResponseStatus PROCESSING = newStatus(102, "Processing");
/** /**
* 200 OK * 200 OK
*/ */
public static final HttpResponseStatus OK = httpResponseStatus(200, "OK"); public static final HttpResponseStatus OK = newStatus(200, "OK");
/** /**
* 201 Created * 201 Created
*/ */
public static final HttpResponseStatus CREATED = httpResponseStatus(201, "Created"); public static final HttpResponseStatus CREATED = newStatus(201, "Created");
/** /**
* 202 Accepted * 202 Accepted
*/ */
public static final HttpResponseStatus ACCEPTED = httpResponseStatus(202, "Accepted"); public static final HttpResponseStatus ACCEPTED = newStatus(202, "Accepted");
/** /**
* 203 Non-Authoritative Information (since HTTP/1.1) * 203 Non-Authoritative Information (since HTTP/1.1)
*/ */
public static final HttpResponseStatus NON_AUTHORITATIVE_INFORMATION = public static final HttpResponseStatus NON_AUTHORITATIVE_INFORMATION =
httpResponseStatus(203, "Non-Authoritative Information"); newStatus(203, "Non-Authoritative Information");
/** /**
* 204 No Content * 204 No Content
*/ */
public static final HttpResponseStatus NO_CONTENT = httpResponseStatus(204, "No Content"); public static final HttpResponseStatus NO_CONTENT = newStatus(204, "No Content");
/** /**
* 205 Reset Content * 205 Reset Content
*/ */
public static final HttpResponseStatus RESET_CONTENT = httpResponseStatus(205, "Reset Content"); public static final HttpResponseStatus RESET_CONTENT = newStatus(205, "Reset Content");
/** /**
* 206 Partial Content * 206 Partial Content
*/ */
public static final HttpResponseStatus PARTIAL_CONTENT = httpResponseStatus(206, "Partial Content"); public static final HttpResponseStatus PARTIAL_CONTENT = newStatus(206, "Partial Content");
/** /**
* 207 Multi-Status (WebDAV, RFC2518) * 207 Multi-Status (WebDAV, RFC2518)
*/ */
public static final HttpResponseStatus MULTI_STATUS = httpResponseStatus(207, "Multi-Status"); public static final HttpResponseStatus MULTI_STATUS = newStatus(207, "Multi-Status");
/** /**
* 300 Multiple Choices * 300 Multiple Choices
*/ */
public static final HttpResponseStatus MULTIPLE_CHOICES = httpResponseStatus(300, "Multiple Choices"); public static final HttpResponseStatus MULTIPLE_CHOICES = newStatus(300, "Multiple Choices");
/** /**
* 301 Moved Permanently * 301 Moved Permanently
*/ */
public static final HttpResponseStatus MOVED_PERMANENTLY = httpResponseStatus(301, "Moved Permanently"); public static final HttpResponseStatus MOVED_PERMANENTLY = newStatus(301, "Moved Permanently");
/** /**
* 302 Found * 302 Found
*/ */
public static final HttpResponseStatus FOUND = httpResponseStatus(302, "Found"); public static final HttpResponseStatus FOUND = newStatus(302, "Found");
/** /**
* 303 See Other (since HTTP/1.1) * 303 See Other (since HTTP/1.1)
*/ */
public static final HttpResponseStatus SEE_OTHER = httpResponseStatus(303, "See Other"); public static final HttpResponseStatus SEE_OTHER = newStatus(303, "See Other");
/** /**
* 304 Not Modified * 304 Not Modified
*/ */
public static final HttpResponseStatus NOT_MODIFIED = httpResponseStatus(304, "Not Modified"); public static final HttpResponseStatus NOT_MODIFIED = newStatus(304, "Not Modified");
/** /**
* 305 Use Proxy (since HTTP/1.1) * 305 Use Proxy (since HTTP/1.1)
*/ */
public static final HttpResponseStatus USE_PROXY = httpResponseStatus(305, "Use Proxy"); public static final HttpResponseStatus USE_PROXY = newStatus(305, "Use Proxy");
/** /**
* 307 Temporary Redirect (since HTTP/1.1) * 307 Temporary Redirect (since HTTP/1.1)
*/ */
public static final HttpResponseStatus TEMPORARY_REDIRECT = httpResponseStatus(307, "Temporary Redirect"); public static final HttpResponseStatus TEMPORARY_REDIRECT = newStatus(307, "Temporary Redirect");
/** /**
* 400 Bad Request * 400 Bad Request
*/ */
public static final HttpResponseStatus BAD_REQUEST = httpResponseStatus(400, "Bad Request"); public static final HttpResponseStatus BAD_REQUEST = newStatus(400, "Bad Request");
/** /**
* 401 Unauthorized * 401 Unauthorized
*/ */
public static final HttpResponseStatus UNAUTHORIZED = httpResponseStatus(401, "Unauthorized"); public static final HttpResponseStatus UNAUTHORIZED = newStatus(401, "Unauthorized");
/** /**
* 402 Payment Required * 402 Payment Required
*/ */
public static final HttpResponseStatus PAYMENT_REQUIRED = httpResponseStatus(402, "Payment Required"); public static final HttpResponseStatus PAYMENT_REQUIRED = newStatus(402, "Payment Required");
/** /**
* 403 Forbidden * 403 Forbidden
*/ */
public static final HttpResponseStatus FORBIDDEN = httpResponseStatus(403, "Forbidden"); public static final HttpResponseStatus FORBIDDEN = newStatus(403, "Forbidden");
/** /**
* 404 Not Found * 404 Not Found
*/ */
public static final HttpResponseStatus NOT_FOUND = httpResponseStatus(404, "Not Found"); public static final HttpResponseStatus NOT_FOUND = newStatus(404, "Not Found");
/** /**
* 405 Method Not Allowed * 405 Method Not Allowed
*/ */
public static final HttpResponseStatus METHOD_NOT_ALLOWED = httpResponseStatus(405, "Method Not Allowed"); public static final HttpResponseStatus METHOD_NOT_ALLOWED = newStatus(405, "Method Not Allowed");
/** /**
* 406 Not Acceptable * 406 Not Acceptable
*/ */
public static final HttpResponseStatus NOT_ACCEPTABLE = httpResponseStatus(406, "Not Acceptable"); public static final HttpResponseStatus NOT_ACCEPTABLE = newStatus(406, "Not Acceptable");
/** /**
* 407 Proxy Authentication Required * 407 Proxy Authentication Required
*/ */
public static final HttpResponseStatus PROXY_AUTHENTICATION_REQUIRED = public static final HttpResponseStatus PROXY_AUTHENTICATION_REQUIRED =
httpResponseStatus(407, "Proxy Authentication Required"); newStatus(407, "Proxy Authentication Required");
/** /**
* 408 Request Timeout * 408 Request Timeout
*/ */
public static final HttpResponseStatus REQUEST_TIMEOUT = httpResponseStatus(408, "Request Timeout"); public static final HttpResponseStatus REQUEST_TIMEOUT = newStatus(408, "Request Timeout");
/** /**
* 409 Conflict * 409 Conflict
*/ */
public static final HttpResponseStatus CONFLICT = httpResponseStatus(409, "Conflict"); public static final HttpResponseStatus CONFLICT = newStatus(409, "Conflict");
/** /**
* 410 Gone * 410 Gone
*/ */
public static final HttpResponseStatus GONE = httpResponseStatus(410, "Gone"); public static final HttpResponseStatus GONE = newStatus(410, "Gone");
/** /**
* 411 Length Required * 411 Length Required
*/ */
public static final HttpResponseStatus LENGTH_REQUIRED = httpResponseStatus(411, "Length Required"); public static final HttpResponseStatus LENGTH_REQUIRED = newStatus(411, "Length Required");
/** /**
* 412 Precondition Failed * 412 Precondition Failed
*/ */
public static final HttpResponseStatus PRECONDITION_FAILED = httpResponseStatus(412, "Precondition Failed"); public static final HttpResponseStatus PRECONDITION_FAILED = newStatus(412, "Precondition Failed");
/** /**
* 413 Request Entity Too Large * 413 Request Entity Too Large
*/ */
public static final HttpResponseStatus REQUEST_ENTITY_TOO_LARGE = public static final HttpResponseStatus REQUEST_ENTITY_TOO_LARGE =
httpResponseStatus(413, "Request Entity Too Large"); newStatus(413, "Request Entity Too Large");
/** /**
* 414 Request-URI Too Long * 414 Request-URI Too Long
*/ */
public static final HttpResponseStatus REQUEST_URI_TOO_LONG = httpResponseStatus(414, "Request-URI Too Long"); public static final HttpResponseStatus REQUEST_URI_TOO_LONG = newStatus(414, "Request-URI Too Long");
/** /**
* 415 Unsupported Media Type * 415 Unsupported Media Type
*/ */
public static final HttpResponseStatus UNSUPPORTED_MEDIA_TYPE = httpResponseStatus(415, "Unsupported Media Type"); public static final HttpResponseStatus UNSUPPORTED_MEDIA_TYPE = newStatus(415, "Unsupported Media Type");
/** /**
* 416 Requested Range Not Satisfiable * 416 Requested Range Not Satisfiable
*/ */
public static final HttpResponseStatus REQUESTED_RANGE_NOT_SATISFIABLE = public static final HttpResponseStatus REQUESTED_RANGE_NOT_SATISFIABLE =
httpResponseStatus(416, "Requested Range Not Satisfiable"); newStatus(416, "Requested Range Not Satisfiable");
/** /**
* 417 Expectation Failed * 417 Expectation Failed
*/ */
public static final HttpResponseStatus EXPECTATION_FAILED = httpResponseStatus(417, "Expectation Failed"); public static final HttpResponseStatus EXPECTATION_FAILED = newStatus(417, "Expectation Failed");
/** /**
* 421 Misdirected Request * 421 Misdirected Request
* *
* <a href="https://tools.ietf.org/html/draft-ietf-httpbis-http2-15#section-9.1.2">421 Status Code</a> * <a href="https://tools.ietf.org/html/draft-ietf-httpbis-http2-15#section-9.1.2">421 Status Code</a>
*/ */
public static final HttpResponseStatus MISDIRECTED_REQUEST = httpResponseStatus(421, "Misdirected Request"); public static final HttpResponseStatus MISDIRECTED_REQUEST = newStatus(421, "Misdirected Request");
/** /**
* 422 Unprocessable Entity (WebDAV, RFC4918) * 422 Unprocessable Entity (WebDAV, RFC4918)
*/ */
public static final HttpResponseStatus UNPROCESSABLE_ENTITY = httpResponseStatus(422, "Unprocessable Entity"); public static final HttpResponseStatus UNPROCESSABLE_ENTITY = newStatus(422, "Unprocessable Entity");
/** /**
* 423 Locked (WebDAV, RFC4918) * 423 Locked (WebDAV, RFC4918)
*/ */
public static final HttpResponseStatus LOCKED = httpResponseStatus(423, "Locked"); public static final HttpResponseStatus LOCKED = newStatus(423, "Locked");
/** /**
* 424 Failed Dependency (WebDAV, RFC4918) * 424 Failed Dependency (WebDAV, RFC4918)
*/ */
public static final HttpResponseStatus FAILED_DEPENDENCY = httpResponseStatus(424, "Failed Dependency"); public static final HttpResponseStatus FAILED_DEPENDENCY = newStatus(424, "Failed Dependency");
/** /**
* 425 Unordered Collection (WebDAV, RFC3648) * 425 Unordered Collection (WebDAV, RFC3648)
*/ */
public static final HttpResponseStatus UNORDERED_COLLECTION = httpResponseStatus(425, "Unordered Collection"); public static final HttpResponseStatus UNORDERED_COLLECTION = newStatus(425, "Unordered Collection");
/** /**
* 426 Upgrade Required (RFC2817) * 426 Upgrade Required (RFC2817)
*/ */
public static final HttpResponseStatus UPGRADE_REQUIRED = httpResponseStatus(426, "Upgrade Required"); public static final HttpResponseStatus UPGRADE_REQUIRED = newStatus(426, "Upgrade Required");
/** /**
* 428 Precondition Required (RFC6585) * 428 Precondition Required (RFC6585)
*/ */
public static final HttpResponseStatus PRECONDITION_REQUIRED = httpResponseStatus(428, "Precondition Required"); public static final HttpResponseStatus PRECONDITION_REQUIRED = newStatus(428, "Precondition Required");
/** /**
* 429 Too Many Requests (RFC6585) * 429 Too Many Requests (RFC6585)
*/ */
public static final HttpResponseStatus TOO_MANY_REQUESTS = httpResponseStatus(429, "Too Many Requests"); public static final HttpResponseStatus TOO_MANY_REQUESTS = newStatus(429, "Too Many Requests");
/** /**
* 431 Request Header Fields Too Large (RFC6585) * 431 Request Header Fields Too Large (RFC6585)
*/ */
public static final HttpResponseStatus REQUEST_HEADER_FIELDS_TOO_LARGE = public static final HttpResponseStatus REQUEST_HEADER_FIELDS_TOO_LARGE =
httpResponseStatus(431, "Request Header Fields Too Large"); newStatus(431, "Request Header Fields Too Large");
/** /**
* 500 Internal Server Error * 500 Internal Server Error
*/ */
public static final HttpResponseStatus INTERNAL_SERVER_ERROR = httpResponseStatus(500, "Internal Server Error"); public static final HttpResponseStatus INTERNAL_SERVER_ERROR = newStatus(500, "Internal Server Error");
/** /**
* 501 Not Implemented * 501 Not Implemented
*/ */
public static final HttpResponseStatus NOT_IMPLEMENTED = httpResponseStatus(501, "Not Implemented"); public static final HttpResponseStatus NOT_IMPLEMENTED = newStatus(501, "Not Implemented");
/** /**
* 502 Bad Gateway * 502 Bad Gateway
*/ */
public static final HttpResponseStatus BAD_GATEWAY = httpResponseStatus(502, "Bad Gateway"); public static final HttpResponseStatus BAD_GATEWAY = newStatus(502, "Bad Gateway");
/** /**
* 503 Service Unavailable * 503 Service Unavailable
*/ */
public static final HttpResponseStatus SERVICE_UNAVAILABLE = httpResponseStatus(503, "Service Unavailable"); public static final HttpResponseStatus SERVICE_UNAVAILABLE = newStatus(503, "Service Unavailable");
/** /**
* 504 Gateway Timeout * 504 Gateway Timeout
*/ */
public static final HttpResponseStatus GATEWAY_TIMEOUT = httpResponseStatus(504, "Gateway Timeout"); public static final HttpResponseStatus GATEWAY_TIMEOUT = newStatus(504, "Gateway Timeout");
/** /**
* 505 HTTP Version Not Supported * 505 HTTP Version Not Supported
*/ */
public static final HttpResponseStatus HTTP_VERSION_NOT_SUPPORTED = public static final HttpResponseStatus HTTP_VERSION_NOT_SUPPORTED =
httpResponseStatus(505, "HTTP Version Not Supported"); newStatus(505, "HTTP Version Not Supported");
/** /**
* 506 Variant Also Negotiates (RFC2295) * 506 Variant Also Negotiates (RFC2295)
*/ */
public static final HttpResponseStatus VARIANT_ALSO_NEGOTIATES = httpResponseStatus(506, "Variant Also Negotiates"); public static final HttpResponseStatus VARIANT_ALSO_NEGOTIATES = newStatus(506, "Variant Also Negotiates");
/** /**
* 507 Insufficient Storage (WebDAV, RFC4918) * 507 Insufficient Storage (WebDAV, RFC4918)
*/ */
public static final HttpResponseStatus INSUFFICIENT_STORAGE = httpResponseStatus(507, "Insufficient Storage"); public static final HttpResponseStatus INSUFFICIENT_STORAGE = newStatus(507, "Insufficient Storage");
/** /**
* 510 Not Extended (RFC2774) * 510 Not Extended (RFC2774)
*/ */
public static final HttpResponseStatus NOT_EXTENDED = httpResponseStatus(510, "Not Extended"); public static final HttpResponseStatus NOT_EXTENDED = newStatus(510, "Not Extended");
/** /**
* 511 Network Authentication Required (RFC6585) * 511 Network Authentication Required (RFC6585)
*/ */
public static final HttpResponseStatus NETWORK_AUTHENTICATION_REQUIRED = public static final HttpResponseStatus NETWORK_AUTHENTICATION_REQUIRED =
httpResponseStatus(511, "Network Authentication Required"); newStatus(511, "Network Authentication Required");
private static HttpResponseStatus newStatus(int statusCode, String reasonPhrase) {
return new HttpResponseStatus(statusCode, reasonPhrase, true);
}
/** /**
* Returns the {@link HttpResponseStatus} represented by the specified code. * Returns the {@link HttpResponseStatus} represented by the specified code.
@ -483,7 +487,7 @@ public class HttpResponseStatus implements Comparable<HttpResponseStatus> {
} }
private final int code; private final int code;
private final AsciiString codeAsString; private final AsciiString codeAsText;
private final String reasonPhrase; private final String reasonPhrase;
private final byte[] bytes; private final byte[] bytes;
@ -518,7 +522,7 @@ public class HttpResponseStatus implements Comparable<HttpResponseStatus> {
} }
this.code = code; this.code = code;
codeAsString = new AsciiString(Integer.toString(code)); codeAsText = new AsciiString(Integer.toString(code));
this.reasonPhrase = reasonPhrase; this.reasonPhrase = reasonPhrase;
if (bytes) { if (bytes) {
this.bytes = (code + " " + reasonPhrase).getBytes(CharsetUtil.US_ASCII); this.bytes = (code + " " + reasonPhrase).getBytes(CharsetUtil.US_ASCII);
@ -538,7 +542,7 @@ public class HttpResponseStatus implements Comparable<HttpResponseStatus> {
* Returns the status code as {@link AsciiString}. * Returns the status code as {@link AsciiString}.
*/ */
public AsciiString codeAsText() { public AsciiString codeAsText() {
return codeAsString; return codeAsText;
} }
/** /**
@ -593,8 +597,4 @@ public class HttpResponseStatus implements Comparable<HttpResponseStatus> {
buf.writeBytes(bytes); buf.writeBytes(bytes);
} }
} }
private static HttpResponseStatus httpResponseStatus(int statusCode, String reasonPhrase) {
return new HttpResponseStatus(statusCode, reasonPhrase, true);
}
} }