From aa0a8f17c83104f99cbc2033e4445f5ed0655bdc Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Fri, 19 Jun 2009 14:15:20 +0000 Subject: [PATCH] * Added HttpMessage.isKeepAlive() * Javadoc --- .../handler/codec/http/DefaultCookie.java | 5 + .../handler/codec/http/DefaultHttpChunk.java | 6 + .../codec/http/DefaultHttpMessage.java | 17 +- .../codec/http/DefaultHttpRequest.java | 11 +- .../codec/http/DefaultHttpResponse.java | 8 +- .../netty/handler/codec/http/HttpHeaders.java | 238 +++++++++++++++++- .../netty/handler/codec/http/HttpMessage.java | 108 ++++++-- .../netty/handler/codec/http/HttpMethod.java | 21 +- .../netty/handler/codec/http/HttpRequest.java | 10 +- .../handler/codec/http/HttpResponse.java | 9 +- .../codec/http/HttpResponseStatus.java | 137 +++++++++- .../netty/handler/codec/http/HttpVersion.java | 52 +++- 12 files changed, 595 insertions(+), 27 deletions(-) diff --git a/src/main/java/org/jboss/netty/handler/codec/http/DefaultCookie.java b/src/main/java/org/jboss/netty/handler/codec/http/DefaultCookie.java index 65d6605b5e..c2a610c4ee 100644 --- a/src/main/java/org/jboss/netty/handler/codec/http/DefaultCookie.java +++ b/src/main/java/org/jboss/netty/handler/codec/http/DefaultCookie.java @@ -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"); diff --git a/src/main/java/org/jboss/netty/handler/codec/http/DefaultHttpChunk.java b/src/main/java/org/jboss/netty/handler/codec/http/DefaultHttpChunk.java index 7011d06ddd..f1839b4cd1 100644 --- a/src/main/java/org/jboss/netty/handler/codec/http/DefaultHttpChunk.java +++ b/src/main/java/org/jboss/netty/handler/codec/http/DefaultHttpChunk.java @@ -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"); diff --git a/src/main/java/org/jboss/netty/handler/codec/http/DefaultHttpMessage.java b/src/main/java/org/jboss/netty/handler/codec/http/DefaultHttpMessage.java index a23ce7d480..6534050a89 100644 --- a/src/main/java/org/jboss/netty/handler/codec/http/DefaultHttpMessage.java +++ b/src/main/java/org/jboss/netty/handler/codec/http/DefaultHttpMessage.java @@ -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> headers = new TreeMap>(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(); } diff --git a/src/main/java/org/jboss/netty/handler/codec/http/DefaultHttpRequest.java b/src/main/java/org/jboss/netty/handler/codec/http/DefaultHttpRequest.java index 3bb4a23063..54327ee904 100644 --- a/src/main/java/org/jboss/netty/handler/codec/http/DefaultHttpRequest.java +++ b/src/main/java/org/jboss/netty/handler/codec/http/DefaultHttpRequest.java @@ -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) { diff --git a/src/main/java/org/jboss/netty/handler/codec/http/DefaultHttpResponse.java b/src/main/java/org/jboss/netty/handler/codec/http/DefaultHttpResponse.java index cef98150eb..ffc6285c87 100644 --- a/src/main/java/org/jboss/netty/handler/codec/http/DefaultHttpResponse.java +++ b/src/main/java/org/jboss/netty/handler/codec/http/DefaultHttpResponse.java @@ -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) { diff --git a/src/main/java/org/jboss/netty/handler/codec/http/HttpHeaders.java b/src/main/java/org/jboss/netty/handler/codec/http/HttpHeaders.java index 74582caf9d..b0a3907a2c 100644 --- a/src/main/java/org/jboss/netty/handler/codec/http/HttpHeaders.java +++ b/src/main/java/org/jboss/netty/handler/codec/http/HttpHeaders.java @@ -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() { diff --git a/src/main/java/org/jboss/netty/handler/codec/http/HttpMessage.java b/src/main/java/org/jboss/netty/handler/codec/http/HttpMessage.java index fe600994ad..03786051b7 100644 --- a/src/main/java/org/jboss/netty/handler/codec/http/HttpMessage.java +++ b/src/main/java/org/jboss/netty/handler/codec/http/HttpMessage.java @@ -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 HTTP + * 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 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 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 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 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(); } diff --git a/src/main/java/org/jboss/netty/handler/codec/http/HttpMethod.java b/src/main/java/org/jboss/netty/handler/codec/http/HttpMethod.java index 0af8dc47bb..aca6a33b46 100644 --- a/src/main/java/org/jboss/netty/handler/codec/http/HttpMethod.java +++ b/src/main/java/org/jboss/netty/handler/codec/http/HttpMethod.java @@ -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 HTTP + * or its derived protocols, such as + * RTSP and + * ICAP. * * @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 { 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 { private final String name; + /** + * Creates a new HTTP + * method with the specified name. You will not need to create a new method + * unless you are implementing a protocol derived from + * HTTP, such as + * RTSP and + * ICAP + */ public HttpMethod(String name) { if (name == null) { throw new NullPointerException("name"); @@ -134,6 +150,9 @@ public class HttpMethod implements Comparable { this.name = name; } + /** + * Returns the name of this method. + */ public String getName() { return name; } diff --git a/src/main/java/org/jboss/netty/handler/codec/http/HttpRequest.java b/src/main/java/org/jboss/netty/handler/codec/http/HttpRequest.java index 65cc64ceec..4aebe03ad8 100644 --- a/src/main/java/org/jboss/netty/handler/codec/http/HttpRequest.java +++ b/src/main/java/org/jboss/netty/handler/codec/http/HttpRequest.java @@ -23,18 +23,26 @@ package org.jboss.netty.handler.codec.http; /** - * An http request. + * An HTTP + * 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(); } diff --git a/src/main/java/org/jboss/netty/handler/codec/http/HttpResponse.java b/src/main/java/org/jboss/netty/handler/codec/http/HttpResponse.java index acebbe0460..4d99472efd 100644 --- a/src/main/java/org/jboss/netty/handler/codec/http/HttpResponse.java +++ b/src/main/java/org/jboss/netty/handler/codec/http/HttpResponse.java @@ -23,13 +23,20 @@ package org.jboss.netty.handler.codec.http; /** - * an http response. + * An HTTP + * 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(); } diff --git a/src/main/java/org/jboss/netty/handler/codec/http/HttpResponseStatus.java b/src/main/java/org/jboss/netty/handler/codec/http/HttpResponseStatus.java index 2af85340b1..1b318b5cdb 100644 --- a/src/main/java/org/jboss/netty/handler/codec/http/HttpResponseStatus.java +++ b/src/main/java/org/jboss/netty/handler/codec/http/HttpResponseStatus.java @@ -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 + * HTTP + * or its derived protocols, such as + * RTSP and + * ICAP. * * @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 { + /** + * 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; } diff --git a/src/main/java/org/jboss/netty/handler/codec/http/HttpVersion.java b/src/main/java/org/jboss/netty/handler/codec/http/HttpVersion.java index bc155300c9..7eb3424d2b 100644 --- a/src/main/java/org/jboss/netty/handler/codec/http/HttpVersion.java +++ b/src/main/java/org/jboss/netty/handler/codec/http/HttpVersion.java @@ -25,7 +25,10 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; /** - * The protocols we support; + * Represents the version of HTTP + * or its derived protocols, such as + * RTSP and + * ICAP. * * @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 { 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 { 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 + * RTSP and + * ICAP. + */ public HttpVersion(String text) { if (text == null) { throw new NullPointerException("text"); @@ -83,6 +108,16 @@ public class HttpVersion implements Comparable { this.text = protocolName + '/' + majorVersion + '.' + minorVersion; } + /** + * Creates a new + * HTTP + * 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 HTTP, + * such as + * RTSP and + * ICAP + */ public HttpVersion( String protocolName, int majorVersion, int minorVersion) { if (protocolName == null) { @@ -114,22 +149,37 @@ public class HttpVersion implements Comparable { 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();