* Added HttpMessage.isKeepAlive()

* Javadoc
This commit is contained in:
Trustin Lee 2009-06-19 14:15:20 +00:00
parent 120eeabc79
commit aa0a8f17c8
12 changed files with 595 additions and 27 deletions

View File

@ -29,6 +29,8 @@ import org.jboss.netty.util.internal.CaseIgnoringComparator;
/**
* The default {@link Cookie} implementation.
*
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Andy Taylor (andy.taylor@jboss.org)
* @author Trustin Lee (tlee@redhat.com)
@ -64,6 +66,9 @@ public class DefaultCookie implements Cookie {
private int version;
private boolean secure;
/**
* Creates a new cookie with the specified name and value.
*/
public DefaultCookie(String name, String value) {
if (name == null) {
throw new NullPointerException("name");

View File

@ -25,6 +25,8 @@ package org.jboss.netty.handler.codec.http;
import org.jboss.netty.buffer.ChannelBuffer;
/**
* The default {@link HttpChunk} implementation.
*
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Trustin Lee (tlee@redhat.com)
* @version $Rev$, $Date$
@ -34,6 +36,10 @@ public class DefaultHttpChunk implements HttpChunk {
private final ChannelBuffer content;
private final boolean last;
/**
* Creates a new instance with the specified chunk content. If an empty
* buffer is specified, this chunk becomes the 'end of chunk' marker.
*/
public DefaultHttpChunk(ChannelBuffer content) {
if (content == null) {
throw new NullPointerException("content");

View File

@ -33,7 +33,7 @@ import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.util.internal.CaseIgnoringComparator;
/**
* a default Http Message which holds the headers and body.
* The default {@link HttpMessage} implementation.
*
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Andy Taylor (andy.taylor@jboss.org)
@ -46,6 +46,9 @@ public class DefaultHttpMessage implements HttpMessage {
private final Map<String, List<String>> headers = new TreeMap<String, List<String>>(CaseIgnoringComparator.INSTANCE);
private ChannelBuffer content = ChannelBuffers.EMPTY_BUFFER;
/**
* Creates a new instance.
*/
protected DefaultHttpMessage(final HttpVersion version) {
if (version == null) {
throw new NullPointerException("version");
@ -174,6 +177,18 @@ public class DefaultHttpMessage implements HttpMessage {
return false;
}
public boolean isKeepAlive() {
if (HttpHeaders.Values.CLOSE.equalsIgnoreCase(getHeader(HttpHeaders.Names.CONNECTION))) {
return false;
}
if (getProtocolVersion().equals(HttpVersion.HTTP_1_0) &&
!HttpHeaders.Values.KEEP_ALIVE.equalsIgnoreCase(getHeader(HttpHeaders.Names.CONNECTION))) {
return false;
}
return true;
}
public void clearHeaders() {
headers.clear();
}

View File

@ -21,10 +21,8 @@
*/
package org.jboss.netty.handler.codec.http;
/**
* An http request implementation
* The default {@link HttpRequest} implementation.
*
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Andy Taylor (andy.taylor@jboss.org)
@ -36,6 +34,13 @@ public class DefaultHttpRequest extends DefaultHttpMessage implements HttpReques
private final HttpMethod method;
private final String uri;
/**
* Creates a new instance.
*
* @param httpVersion the HTTP version of the request
* @param method the HTTP method of the request
* @param uri the URI or path of the request
*/
public DefaultHttpRequest(HttpVersion httpVersion, HttpMethod method, String uri) {
super(httpVersion);
if (method == null) {

View File

@ -22,7 +22,7 @@
package org.jboss.netty.handler.codec.http;
/**
* an http response implementation
* The default {@link HttpResponse} implementation.
*
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Andy Taylor (andy.taylor@jboss.org)
@ -32,6 +32,12 @@ package org.jboss.netty.handler.codec.http;
public class DefaultHttpResponse extends DefaultHttpMessage implements HttpResponse {
private final HttpResponseStatus status;
/**
* Creates a new instance.
*
* @param version the HTTP version of this response
* @param status the status of this response
*/
public DefaultHttpResponse(HttpVersion version, HttpResponseStatus status) {
super(version);
if (status == null) {

View File

@ -22,61 +22,217 @@
package org.jboss.netty.handler.codec.http;
/**
* The constants that is often used in HTTP header names and values.
*
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Andy Taylor (andy.taylor@jboss.org)
* @version $Rev$, $Date$
*/
public final class HttpHeaders {
// Header names
/**
* The constants that is often used in HTTP header names.
*
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Andy Taylor (andy.taylor@jboss.org)
* @version $Rev$, $Date$
*/
public static final class Names {
/**
* {@code "Accept"}
*/
public static final String ACCEPT = "Accept";
/**
* {@code "Accept-Charset"}
*/
public static final String ACCEPT_CHARSET = "Accept-Charset";
/**
* {@code "Accept-Encoding"}
*/
public static final String ACCEPT_ENCODING= "Accept-Encoding";
/**
* {@code "Accept-Language"}
*/
public static final String ACCEPT_LANGUAGE = "Accept-Language";
/**
* {@code "Accept-Ranges"}
*/
public static final String ACCEPT_RANGES= "Accept-Ranges";
/**
* {@code "Age"}
*/
public static final String AGE = "Age";
/**
* {@code "Allow"}
*/
public static final String ALLOW = "Allow";
/**
* {@code "Authorization"}
*/
public static final String AUTHORIZATION = "Authorization";
/**
* {@code "Cache-Control"}
*/
public static final String CACHE_CONTROL = "Cache-Control";
/**
* {@code "Connection"}
*/
public static final String CONNECTION = "Connection";
/**
* {@code "Content-Encoding"}
*/
public static final String CONTENT_ENCODING = "Content-Encoding";
/**
* {@code "Content-Language"}
*/
public static final String CONTENT_LANGUAGE= "Content-Language";
/**
* {@code "Content-Length"}
*/
public static final String CONTENT_LENGTH = "Content-Length";
/**
* {@code "Content-Location"}
*/
public static final String CONTENT_LOCATION = "Content-Location";
/**
* {@code "Content-MD5"}
*/
public static final String CONTENT_MD5 = "Content-MD5";
/**
* {@code "Content-Range"}
*/
public static final String CONTENT_RANGE = "Content-Range";
/**
* {@code "Content-Type"}
*/
public static final String CONTENT_TYPE= "Content-Type";
/**
* {@code "Cookie"}
*/
public static final String COOKIE = "Cookie";
/**
* {@code "Date"}
*/
public static final String DATE = "Date";
/**
* {@code "ETag"}
*/
public static final String ETAG = "ETag";
/**
* {@code "Expect"}
*/
public static final String EXPECT = "Expect";
/**
* {@code "Expires"}
*/
public static final String EXPIRES = "Expires";
/**
* {@code "From"}
*/
public static final String FROM = "From";
/**
* {@code "Host"}
*/
public static final String HOST = "Host";
/**
* {@code "If-Match"}
*/
public static final String IF_MATCH = "If-Match";
/**
* {@code "If-Modified-Since"}
*/
public static final String IF_MODIFIED_SINCE = "If-Modified-Since";
/**
* {@code "If-None-Match"}
*/
public static final String IF_NONE_MATCH = "If-None-Match";
/**
* {@code "If-Range"}
*/
public static final String IF_RANGE= "If-Range";
/**
* {@code "If-Unmodified-Since"}
*/
public static final String IF_UNMODIFIED_SINCE = "If-Unmodified-Since";
/**
* {@code "Last-Modified"}
*/
public static final String LAST_MODIFIED = "Last-Modified";
/**
* {@code "Location"}
*/
public static final String LOCATION = "Location";
/**
* {@code "Max-Forwards"}
*/
public static final String MAX_FORWARDS = "Max-Forwards";
/**
* {@code "Pragma"}
*/
public static final String PRAGMA = "Pragma";
/**
* {@code "Proxy-Authenticate"}
*/
public static final String PROXY_AUTHENTICATE = "Proxy-Authenticate";
/**
* {@code "Proxy-Authorization"}
*/
public static final String PROXY_AUTHORIZATION = "Proxy-Authorization";
/**
* {@code "Range"}
*/
public static final String RANGE = "Range";
/**
* {@code "Referer"}
*/
public static final String REFERER = "Referer";
/**
* {@code "Retry-After"}
*/
public static final String RETRY_AFTER = "Retry-After";
/**
* {@code "Server"}
*/
public static final String SERVER = "Server";
/**
* {@code "Set-Cookie"}
*/
public static final String SET_COOKIE = "Set-Cookie";
/**
* {@code "TE"}
*/
public static final String TE = "TE";
/**
* {@code "Trailer"}
*/
public static final String TRAILER = "Trailer";
/**
* {@code "Transfer-Encoding"}
*/
public static final String TRANSFER_ENCODING = "Transfer-Encoding";
/**
* {@code "Upgrade"}
*/
public static final String UPGRADE = "Upgrade";
/**
* {@code "User-Agent"}
*/
public static final String USER_AGENT = "User-Agent";
/**
* {@code "Vary"}
*/
public static final String VARY = "Vary";
/**
* {@code "Via"}
*/
public static final String VIA = "Via";
/**
* {@code "Warning"}
*/
public static final String WARNING = "Warning";
/**
* {@code "WWW-Authenticate"}
*/
public static final String WWW_AUTHENTICATE = "WWW-Authenticate";
private Names() {
@ -84,31 +240,109 @@ public final class HttpHeaders {
}
}
// Header values
/**
* The constants that is often used in HTTP header values.
*
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Andy Taylor (andy.taylor@jboss.org)
* @version $Rev$, $Date$
*/
public static final class Values {
/**
* {@code "bytes"}
*/
public static final String BYTES = "bytes";
/**
* {@code "charset"}
*/
public static final String CHARSET = "charset";
/**
* {@code "chunked"}
*/
public static final String CHUNKED = "chunked";
/**
* {@code "close"}
*/
public static final String CLOSE = "close";
/**
* {@code "compress"}
*/
public static final String COMPRESS = "compress";
/**
* {@code "100-continue"}
*/
public static final String CONTINUE = "100-continue";
/**
* {@code "deflate"}
*/
public static final String DEFLATE = "deflate";
/**
* {@code "gzip"}
*/
public static final String GZIP = "gzip";
/**
* {@code "identity"}
*/
public static final String IDENTITY = "identity";
/**
* {@code "keep-alive"}
*/
public static final String KEEP_ALIVE = "keep-alive";
/**
* {@code "max-age"}
*/
public static final String MAX_AGE = "max-age";
/**
* {@code "max-fresh"}
*/
public static final String MAX_FRESH = "max-fresh";
/**
* {@code "max-stale"}
*/
public static final String MAX_STALE = "max-stale";
/**
* {@code "must-revalidate"}
*/
public static final String MUST_REVALIDATE = "must-revalidate";
/**
* {@code "no-cache"}
*/
public static final String NO_CACHE = "no-cache";
/**
* {@code "no-store"}
*/
public static final String NO_STORE = "no-store";
/**
* {@code "no-transform"}
*/
public static final String NO_TRANSFORM = "no-transform";
/**
* {@code "none"}
*/
public static final String NONE = "none";
/**
* {@code "only-if-cached"}
*/
public static final String ONLY_IF_CACHED = "only-if-cached";
/**
* {@code "private"}
*/
public static final String PRIVATE = "private";
/**
* {@code "proxy-revalidate"}
*/
public static final String PROXY_REVALIDATE = "proxy-revalidate";
/**
* {@code "public"}
*/
public static final String PUBLIC = "public";
/**
* {@code "s-maxage"}
*/
public static final String S_MAXAGE = "s-maxage";
/**
* {@code "trailers"}
*/
public static final String TRAILERS = "trailers";
private Values() {

View File

@ -25,9 +25,12 @@ import java.util.List;
import java.util.Set;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
/**
* Encapsulates an Http message. this will contain the protocol version, headers and the body of a message
* An <a href="http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol">HTTP</a>
* message which provides common properties for {@link HttpRequest} and
* {@link HttpResponse}.
*
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Andy Taylor (andy.taylor@jboss.org)
@ -35,34 +38,111 @@ import org.jboss.netty.buffer.ChannelBuffer;
* @version $Rev$, $Date$
*/
public interface HttpMessage {
/**
* Returns the header value with the specified header name. If there are
* more than one header value for the specified header name, the first
* value is returned.
*
* @return the header value or {@code null} if there is no such header
*
*/
String getHeader(String name);
/**
* Returns the header values with the specified header name.
*
* @return the {@link List} of header values of {@code null} if there is
* no such header
*/
List<String> getHeaders(String name);
/**
* Returns {@code true} if and only if there is a header with the specified
* header name.
*/
boolean containsHeader(String name);
/**
* Returns the {@link Set} of all header names that this message contains.
*/
Set<String> getHeaderNames();
/**
* Returns the protocol version of this message.
*/
HttpVersion getProtocolVersion();
/**
* Returns the content of this message. If there is no content, an
* {@link ChannelBuffers#EMPTY_BUFFER} is returned.
*/
ChannelBuffer getContent();
void addHeader(String name, String value);
void setHeader(String name, String value);
void setHeader(String name, Iterable<String> values);
void removeHeader(String name);
long getContentLength();
long getContentLength(long defaultValue);
/**
* Sets the content of this message. If {@code null} is specified,
* the content of this message will be set to {@link ChannelBuffers#EMPTY_BUFFER}.
*/
void setContent(ChannelBuffer content);
boolean isChunked();
/**
* Adds a new header with the specified name and value.
*/
void addHeader(String name, String value);
/**
* Sets a new header with the specified name and value. If there is an
* existing header with the same name, the existing header is removed.
*/
void setHeader(String name, String value);
/**
* Sets a new header with the specified name and values. If there is an
* existing header with the same name, the existing header is removed.
*/
void setHeader(String name, Iterable<String> values);
/**
* Removes the header with the specified name.
*/
void removeHeader(String name);
/**
* Removes all headers from this message.
*/
void clearHeaders();
/**
* Returns the length of the content. Please note that this value is
* not retrieved from {@link #getContent()} but from the
* {@code "Content-Length"} header, and thus they are independent from each
* other.
*
* @return the content length or {@code 0} if this message does not have
* the {@code "Content-Length"} header
*/
long getContentLength();
/**
* Returns the length of the content. Please note that this value is
* not retrieved from {@link #getContent()} but from the
* {@code "Content-Length"} header, and thus they are independent from each
* other.
*
* @return the content length or {@code defaultValue} if this message does
* not have the {@code "Content-Length"} header
*/
long getContentLength(long defaultValue);
/**
* Returns {@code true} if and only if the {@code "Transfer-Encoding"} of
* this message is {@code "chunked"}.
*/
boolean isChunked();
/**
* Returns {@code true} if and only if the connection can remain open and
* thus 'kept alive'.
*/
boolean isKeepAlive();
}

View File

@ -25,7 +25,10 @@ import java.util.HashMap;
import java.util.Map;
/**
* This defines the methods available via a HTTP Request.
* Represents the method of <a href="http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol">HTTP</a>
* or its derived protocols, such as
* <a href="http://en.wikipedia.org/wiki/Real_Time_Streaming_Protocol">RTSP</a> and
* <a href="http://en.wikipedia.org/wiki/Internet_Content_Adaptation_Protocol">ICAP</a>.
*
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Andy Taylor (andy.taylor@jboss.org)
@ -94,6 +97,11 @@ public class HttpMethod implements Comparable<HttpMethod> {
methodMap.put(CONNECT.toString(), CONNECT);
}
/**
* Returns the {@link HttpMethod} represented by the specified name.
* If the specified name is a standard HTTP method name, a cached instance
* will be returned. Otherwise, a new instance will be returned.
*/
public static HttpMethod valueOf(String name) {
if (name == null) {
throw new NullPointerException("name");
@ -114,6 +122,14 @@ public class HttpMethod implements Comparable<HttpMethod> {
private final String name;
/**
* Creates a new <a href="http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol">HTTP</a>
* method with the specified name. You will not need to create a new method
* unless you are implementing a protocol derived from
* <a href="http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol">HTTP</a>, such as
* <a href="http://en.wikipedia.org/wiki/Real_Time_Streaming_Protocol">RTSP</a> and
* <a href="http://en.wikipedia.org/wiki/Internet_Content_Adaptation_Protocol">ICAP</a>
*/
public HttpMethod(String name) {
if (name == null) {
throw new NullPointerException("name");
@ -134,6 +150,9 @@ public class HttpMethod implements Comparable<HttpMethod> {
this.name = name;
}
/**
* Returns the name of this method.
*/
public String getName() {
return name;
}

View File

@ -23,18 +23,26 @@ package org.jboss.netty.handler.codec.http;
/**
* An http request.
* An <a href="http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol">HTTP</a>
* request.
*
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Andy Taylor (andy.taylor@jboss.org)
* @version $Rev$, $Date$
*
* @see HttpResponse
* @see QueryStringEncoder
* @see QueryStringDecoder
*/
public interface HttpRequest extends HttpMessage {
/**
* Returns the method of this request.
*/
HttpMethod getMethod();
/**
* Returns the URI (or path) of this request.
*/
String getUri();
}

View File

@ -23,13 +23,20 @@ package org.jboss.netty.handler.codec.http;
/**
* an http response.
* An <a href="http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol">HTTP</a>
* response.
*
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Andy Taylor (andy.taylor@jboss.org)
* @author Trustin Lee (tlee@redhat.com)
* @version $Rev$, $Date$
*
* @see HttpRequest
*/
public interface HttpResponse extends HttpMessage {
/**
* Returns the status of this response.
*/
HttpResponseStatus getStatus();
}

View File

@ -23,7 +23,11 @@ package org.jboss.netty.handler.codec.http;
/**
* The response codes and descriptions to return in the response. see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
* Represents the response code and its description of
* <a href="http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol">HTTP</a>
* or its derived protocols, such as
* <a href="http://en.wikipedia.org/wiki/Real_Time_Streaming_Protocol">RTSP</a> and
* <a href="http://en.wikipedia.org/wiki/Internet_Content_Adaptation_Protocol">ICAP</a>.
*
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Andy Taylor (andy.taylor@jboss.org)
@ -34,100 +38,229 @@ package org.jboss.netty.handler.codec.http;
*/
public class HttpResponseStatus implements Comparable<HttpResponseStatus> {
/**
* 100 Continue
*/
public static final HttpResponseStatus CONTINUE = new HttpResponseStatus(100, "Continue");
/**
* 101 Switching Protocols
*/
public static final HttpResponseStatus SWITCHING_PROTOCOLS = new HttpResponseStatus(101, "Switching Protocols");
/**
* 200 OK
*/
public static final HttpResponseStatus OK = new HttpResponseStatus(200, "OK");
/**
* 201 Created
*/
public static final HttpResponseStatus CREATED = new HttpResponseStatus(201, "Created");
/**
* 202 Accepted
*/
public static final HttpResponseStatus ACCEPTED = new HttpResponseStatus(202, "Accepted");
/**
* 203 Non-Authoritative Information
*/
public static final HttpResponseStatus NON_AUTHORITATIVE_INFORMATION = new HttpResponseStatus(203, "Non-Authoritative Information");
/**
* 204 No Content
*/
public static final HttpResponseStatus NO_CONTENT = new HttpResponseStatus(204, "No Content");
/**
* 205 Reset Content
*/
public static final HttpResponseStatus RESET_CONTENT = new HttpResponseStatus(205, "Reset Content");
/**
* 206 Partial Content
*/
public static final HttpResponseStatus PARTIAL_CONTENT = new HttpResponseStatus(206, "Partial Content");
/**
* 300 Multiple Choices
*/
public static final HttpResponseStatus MULTIPLE_CHOICES = new HttpResponseStatus(300, "Multiple Choices");
/**
* 301 Moved Permanently
*/
public static final HttpResponseStatus MOVED_PERMANENTLY = new HttpResponseStatus(301, "Moved Permanently");
/**
* 302 Found
*/
public static final HttpResponseStatus FOUND = new HttpResponseStatus(302, "Found");
/**
* 303 See Other
*/
public static final HttpResponseStatus SEE_OTHER = new HttpResponseStatus(303, "See Other");
/**
* 304 Not Modified
*/
public static final HttpResponseStatus NOT_MODIFIED = new HttpResponseStatus(304, "Not Modified");
/**
* 305 Use Proxy
*/
public static final HttpResponseStatus USE_PROXY = new HttpResponseStatus(305, "Use Proxy");
/**
* 307 Temporary Redirect
*/
public static final HttpResponseStatus TEMPORARY_REDIRECT = new HttpResponseStatus(307, "Temporary Redirect");
/**
* 400 Bad Request
*/
public static final HttpResponseStatus BAD_REQUEST = new HttpResponseStatus(400, "Bad Request");
/**
* 401 Unauthorized
*/
public static final HttpResponseStatus UNUATHORIZED = new HttpResponseStatus(401, "Unauthorized");
/**
* 402 Payment Required
*/
public static final HttpResponseStatus PAYMENT_REQUIRED = new HttpResponseStatus(402, "Payment Required");
/**
* 403 Forbidden
*/
public static final HttpResponseStatus FORBIDDEN = new HttpResponseStatus(403, "Forbidden");
/**
* 404 Not Found
*/
public static final HttpResponseStatus NOT_FOUND = new HttpResponseStatus(404, "Not Found");
/**
* 405 Method Not Allowed
*/
public static final HttpResponseStatus METHOD_NOT_ALLOWED = new HttpResponseStatus(405, "Method Not Allowed");
/**
* 406 Not Acceptable
*/
public static final HttpResponseStatus NOT_ACCEPTABLE = new HttpResponseStatus(406, "Not Acceptable");
/**
* 407 Proxy Authentication Required
*/
public static final HttpResponseStatus PROXY_AUTHENTICATION_REQUIRED = new HttpResponseStatus(407, "Proxy Authentication Required");
/**
* 408 Request Timeout
*/
public static final HttpResponseStatus REQUEST_TIMEOUT = new HttpResponseStatus(408, "Request Timeout");
/**
* 409 Conflict
*/
public static final HttpResponseStatus CONFLICT = new HttpResponseStatus(409, "Conflict");
/**
* 410 Gone
*/
public static final HttpResponseStatus GONE = new HttpResponseStatus(410, "Gone");
/**
* 411 Length Required
*/
public static final HttpResponseStatus LENGTH_REQUIRED = new HttpResponseStatus(411, "Length Required");
/**
* 412 Precondition Failed
*/
public static final HttpResponseStatus PRECONDITION_FAILED = new HttpResponseStatus(412, "Precondition Failed");
/**
* 413 Request Entity Too Large
*/
public static final HttpResponseStatus REQUEST_ENTITY_TOO_LARGE = new HttpResponseStatus(413, "Request Entity Too Large");
/**
* 414 Request-URI Too Long
*/
public static final HttpResponseStatus REQUEST_URI_TOO_LONG = new HttpResponseStatus(414, "Request-URI Too Long");
/**
* 415 Unsupported Media Type
*/
public static final HttpResponseStatus UNSUPPORTED_MEDIA_TYPE = new HttpResponseStatus(415, "Unsupported Media Type");
/**
* 416 Requested Range Not Satisfiable
*/
public static final HttpResponseStatus REQUESTED_RANGE_NOT_SATISFIABLE = new HttpResponseStatus(416, "Requested Range Not Satisfiable");
/**
* 417 Expectation Failed
*/
public static final HttpResponseStatus EXPECTATION_FAILED = new HttpResponseStatus(417, "Expectation Failed");
/**
* 500 Internal Server Error
*/
public static final HttpResponseStatus INTERNAL_SERVER_ERROR = new HttpResponseStatus(500, "Internal Server Error");
/**
* 501 Not Implemented
*/
public static final HttpResponseStatus NOT_IMPLEMENTED = new HttpResponseStatus(501, "Not Implemented");
/**
* 502 Bad Gateway
*/
public static final HttpResponseStatus BAD_GATEWAY = new HttpResponseStatus(502, "Bad Gateway");
/**
* 503 Service Unavailable
*/
public static final HttpResponseStatus SERVICE_UNAVAILABLE = new HttpResponseStatus(503, "Service Unavailable");
/**
* 504 Gateway Timeout
*/
public static final HttpResponseStatus GATEWAY_TIMEOUT = new HttpResponseStatus(504, "Gateway Timeout");
/**
* 505 HTTP Version Not Supported
*/
public static final HttpResponseStatus HTTP_VERSION_NOT_SUPPORTED = new HttpResponseStatus(505, "HTTP Version Not Supported");
private final int code;
private final String reasonPhrase;
/**
* Creates a new instance with the specified {@code code} and its
* {@code reasonPhrase}.
*/
public HttpResponseStatus(int code, String reasonPhrase) {
this.code = code;
this.reasonPhrase = reasonPhrase;
}
/**
* Returns the code of this status.
*/
public int getCode() {
return code;
}
/**
* Returns the reason phrase of this status.
*/
public String getReasonPhrase() {
return reasonPhrase;
}

View File

@ -25,7 +25,10 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* The protocols we support;
* Represents the version of <a href="http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol">HTTP</a>
* or its derived protocols, such as
* <a href="http://en.wikipedia.org/wiki/Real_Time_Streaming_Protocol">RTSP</a> and
* <a href="http://en.wikipedia.org/wiki/Internet_Content_Adaptation_Protocol">ICAP</a>.
*
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Andy Taylor (andy.taylor@jboss.org)
@ -39,9 +42,24 @@ public class HttpVersion implements Comparable<HttpVersion> {
private static final Pattern VERSION_PATTERN =
Pattern.compile("(\\S+)/(\\d+)\\.(\\d+)");
/**
* HTTP/1.0
*/
public static final HttpVersion HTTP_1_0 = new HttpVersion("HTTP", 1, 0);
/**
* HTTP/1.1
*/
public static final HttpVersion HTTP_1_1 = new HttpVersion("HTTP", 1, 1);
/**
* Returns an existing or new {@link HttpVersion} instance which matches to
* the specified protocol version string. If the specified {@code text} is
* equal to {@code "HTTP/1.0"}, {@link #HTTP_1_0} will be returned. If the
* specified {@code text} is equal to {@code "HTTP/1.1"}, {@link #HTTP_1_1}
* will be returned. Otherwise, a new {@link HttpVersion} instance will be
* returned.
*/
public static HttpVersion valueOf(String text) {
if (text == null) {
throw new NullPointerException("text");
@ -62,6 +80,13 @@ public class HttpVersion implements Comparable<HttpVersion> {
private final int minorVersion;
private final String text;
/**
* Creates a new HTTP version with the specified version string. You will
* not need to create a new instance unless you are implementing a protocol
* derived from HTTP, such as
* <a href="http://en.wikipedia.org/wiki/Real_Time_Streaming_Protocol">RTSP</a> and
* <a href="http://en.wikipedia.org/wiki/Internet_Content_Adaptation_Protocol">ICAP</a>.
*/
public HttpVersion(String text) {
if (text == null) {
throw new NullPointerException("text");
@ -83,6 +108,16 @@ public class HttpVersion implements Comparable<HttpVersion> {
this.text = protocolName + '/' + majorVersion + '.' + minorVersion;
}
/**
* Creates a new
* <a href="http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol">HTTP</a>
* version with the specified protocol name and version numbers. You will
* not need to create a new instance unless you are implementing a protocol
* derived from <a href="http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol">HTTP</a>,
* such as
* <a href="http://en.wikipedia.org/wiki/Real_Time_Streaming_Protocol">RTSP</a> and
* <a href="http://en.wikipedia.org/wiki/Internet_Content_Adaptation_Protocol">ICAP</a>
*/
public HttpVersion(
String protocolName, int majorVersion, int minorVersion) {
if (protocolName == null) {
@ -114,22 +149,37 @@ public class HttpVersion implements Comparable<HttpVersion> {
text = protocolName + '/' + majorVersion + '.' + minorVersion;
}
/**
* Returns the name of the protocol such as {@code "HTTP"} in {@code "HTTP/1.0"}.
*/
public String getProtocolName() {
return protocolName;
}
/**
* Returns the name of the protocol such as {@code 1} in {@code "HTTP/1.0"}.
*/
public int getMajorVersion() {
return majorVersion;
}
/**
* Returns the name of the protocol such as {@code 0} in {@code "HTTP/1.0"}.
*/
public int getMinorVersion() {
return minorVersion;
}
/**
* Returns the full protocol version text such as {@code "HTTP/1.0"}.
*/
public String getText() {
return text;
}
/**
* Returns the full protocol version text such as {@code "HTTP/1.0"}.
*/
@Override
public String toString() {
return getText();