Resolved issue: NETTY-124 Clean the constants in HttpHeaders

* Reorganized HttpHeaders and added a bunch of constants
This commit is contained in:
Trustin Lee 2009-02-11 08:48:39 +00:00
parent f44d9eced8
commit 3f009da453
4 changed files with 91 additions and 19 deletions

View File

@ -89,7 +89,7 @@ public class HttpClient {
// Send the HTTP request. // Send the HTTP request.
HttpRequest request = new DefaultHttpRequest( HttpRequest request = new DefaultHttpRequest(
HttpVersion.HTTP_1_0, HttpMethod.GET, uri.toASCIIString()); HttpVersion.HTTP_1_0, HttpMethod.GET, uri.toASCIIString());
request.addHeader(HttpHeaders.HOST, host); request.addHeader(HttpHeaders.Names.HOST, host);
channel.write(request); channel.write(request);

View File

@ -63,7 +63,7 @@ public class HttpRequestHandler extends SimpleChannelHandler {
String message = "and its hello from me"; String message = "and its hello from me";
ChannelBuffer buf = ChannelBuffers.wrappedBuffer(message.getBytes()); ChannelBuffer buf = ChannelBuffers.wrappedBuffer(message.getBytes());
response.setContent(buf); response.setContent(buf);
response.addHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(buf.writerIndex())); response.addHeader(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(buf.writerIndex()));
e.getChannel().write(response); e.getChannel().write(response);
} }
} }

View File

@ -82,7 +82,7 @@ public class DefaultHttpMessage implements HttpMessage {
} }
public int getContentLength() { public int getContentLength() {
List<String> contentLength = headers.get(HttpHeaders.CONTENT_LENGTH); List<String> contentLength = headers.get(HttpHeaders.Names.CONTENT_LENGTH);
if (contentLength != null && contentLength.size() > 0) { if (contentLength != null && contentLength.size() > 0) {
return Integer.valueOf(contentLength.get(0)); return Integer.valueOf(contentLength.get(0));
} }
@ -90,8 +90,8 @@ public class DefaultHttpMessage implements HttpMessage {
} }
public boolean isChunked() { public boolean isChunked() {
List<String> chunked = headers.get(HttpHeaders.TRANSFER_ENCODING.KEY); List<String> chunked = headers.get(HttpHeaders.Names.TRANSFER_ENCODING);
return chunked != null && chunked.size() > 0 && chunked.get(0).equalsIgnoreCase(HttpHeaders.TRANSFER_ENCODING.CHUNKED); return chunked != null && chunked.size() > 0 && chunked.get(0).equalsIgnoreCase(HttpHeaders.Values.CHUNKED);
} }
public void clearHeaders() { public void clearHeaders() {

View File

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