2008-11-19 08:22:15 +01:00
|
|
|
/*
|
2009-08-28 09:15:49 +02:00
|
|
|
* Copyright 2009 Red Hat, Inc.
|
2009-06-19 19:48:17 +02:00
|
|
|
*
|
2009-08-28 09:15:49 +02:00
|
|
|
* Red Hat licenses this file to you under the Apache License, version 2.0
|
|
|
|
* (the "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at:
|
2008-11-19 08:22:15 +01:00
|
|
|
*
|
2009-08-28 09:15:49 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2008-11-19 08:22:15 +01:00
|
|
|
*
|
2009-08-28 09:15:49 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2008-11-19 08:22:15 +01:00
|
|
|
*/
|
|
|
|
package org.jboss.netty.handler.codec.http;
|
|
|
|
|
2010-01-08 09:29:37 +01:00
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.TreeSet;
|
|
|
|
|
|
|
|
|
2008-11-19 08:22:15 +01:00
|
|
|
/**
|
2010-01-26 07:30:12 +01:00
|
|
|
* Provides the constants for the standard HTTP header names and values and
|
|
|
|
* commonly used utility methods that accesses an {@link HttpMessage}.
|
2009-06-19 16:15:20 +02:00
|
|
|
*
|
2008-11-19 08:22:15 +01:00
|
|
|
* @author The Netty Project (netty-dev@lists.jboss.org)
|
|
|
|
* @author Andy Taylor (andy.taylor@jboss.org)
|
2008-12-03 10:00:29 +01:00
|
|
|
* @version $Rev$, $Date$
|
2009-07-17 14:49:32 +02:00
|
|
|
*
|
|
|
|
* @apiviz.stereotype static
|
2008-11-19 08:22:15 +01:00
|
|
|
*/
|
2010-01-08 09:29:37 +01:00
|
|
|
public class HttpHeaders {
|
2009-06-19 16:15:20 +02:00
|
|
|
|
|
|
|
/**
|
2009-06-19 16:17:02 +02:00
|
|
|
* Standard HTTP header names.
|
2009-06-19 16:15:20 +02:00
|
|
|
*
|
|
|
|
* @author The Netty Project (netty-dev@lists.jboss.org)
|
|
|
|
* @author Andy Taylor (andy.taylor@jboss.org)
|
|
|
|
* @version $Rev$, $Date$
|
2009-07-17 14:49:32 +02:00
|
|
|
*
|
|
|
|
* @apiviz.stereotype static
|
2009-06-19 16:15:20 +02:00
|
|
|
*/
|
2010-01-26 09:10:34 +01:00
|
|
|
public static final class Names {
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "Accept"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String ACCEPT = "Accept";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "Accept-Charset"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String ACCEPT_CHARSET = "Accept-Charset";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "Accept-Encoding"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String ACCEPT_ENCODING= "Accept-Encoding";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "Accept-Language"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String ACCEPT_LANGUAGE = "Accept-Language";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "Accept-Ranges"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String ACCEPT_RANGES= "Accept-Ranges";
|
2009-12-16 08:23:35 +01:00
|
|
|
/**
|
|
|
|
* {@code "Accept-Patch"}
|
|
|
|
*/
|
|
|
|
public static final String ACCEPT_PATCH= "Accept-Patch";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "Age"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String AGE = "Age";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "Allow"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String ALLOW = "Allow";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "Authorization"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String AUTHORIZATION = "Authorization";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "Cache-Control"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String CACHE_CONTROL = "Cache-Control";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "Connection"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String CONNECTION = "Connection";
|
2010-01-26 09:16:58 +01:00
|
|
|
/**
|
|
|
|
* {@code "Content-Base"}
|
|
|
|
*/
|
|
|
|
public static final String CONTENT_BASE = "Content-Base";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "Content-Encoding"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String CONTENT_ENCODING = "Content-Encoding";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "Content-Language"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String CONTENT_LANGUAGE= "Content-Language";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "Content-Length"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String CONTENT_LENGTH = "Content-Length";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "Content-Location"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String CONTENT_LOCATION = "Content-Location";
|
2009-06-30 11:29:35 +02:00
|
|
|
/**
|
|
|
|
* {@code "Content-Transfer-Encoding"}
|
|
|
|
*/
|
|
|
|
public static final String CONTENT_TRANSFER_ENCODING = "Content-Transfer-Encoding";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "Content-MD5"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String CONTENT_MD5 = "Content-MD5";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "Content-Range"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String CONTENT_RANGE = "Content-Range";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "Content-Type"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String CONTENT_TYPE= "Content-Type";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "Cookie"}
|
|
|
|
*/
|
2009-02-17 18:13:13 +01:00
|
|
|
public static final String COOKIE = "Cookie";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "Date"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String DATE = "Date";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "ETag"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String ETAG = "ETag";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "Expect"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String EXPECT = "Expect";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "Expires"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String EXPIRES = "Expires";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "From"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String FROM = "From";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "Host"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String HOST = "Host";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "If-Match"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String IF_MATCH = "If-Match";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "If-Modified-Since"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String IF_MODIFIED_SINCE = "If-Modified-Since";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "If-None-Match"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String IF_NONE_MATCH = "If-None-Match";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "If-Range"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String IF_RANGE= "If-Range";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "If-Unmodified-Since"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String IF_UNMODIFIED_SINCE = "If-Unmodified-Since";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "Last-Modified"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String LAST_MODIFIED = "Last-Modified";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "Location"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String LOCATION = "Location";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "Max-Forwards"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String MAX_FORWARDS = "Max-Forwards";
|
2010-01-07 08:57:14 +01:00
|
|
|
/**
|
|
|
|
* {@code "Origin"}
|
|
|
|
*/
|
|
|
|
public static final String ORIGIN = "Origin";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "Pragma"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String PRAGMA = "Pragma";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "Proxy-Authenticate"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String PROXY_AUTHENTICATE = "Proxy-Authenticate";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "Proxy-Authorization"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String PROXY_AUTHORIZATION = "Proxy-Authorization";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "Range"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String RANGE = "Range";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "Referer"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String REFERER = "Referer";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "Retry-After"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String RETRY_AFTER = "Retry-After";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "Server"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String SERVER = "Server";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "Set-Cookie"}
|
|
|
|
*/
|
2009-02-17 18:13:13 +01:00
|
|
|
public static final String SET_COOKIE = "Set-Cookie";
|
2009-06-30 11:42:34 +02:00
|
|
|
/**
|
|
|
|
* {@code "Set-Cookie2"}
|
|
|
|
*/
|
|
|
|
public static final String SET_COOKIE2 = "Set-Cookie2";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "TE"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String TE = "TE";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "Trailer"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String TRAILER = "Trailer";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "Transfer-Encoding"}
|
|
|
|
*/
|
2009-02-12 06:14:16 +01:00
|
|
|
public static final String TRANSFER_ENCODING = "Transfer-Encoding";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "Upgrade"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String UPGRADE = "Upgrade";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "User-Agent"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String USER_AGENT = "User-Agent";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "Vary"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String VARY = "Vary";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "Via"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String VIA = "Via";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "Warning"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String WARNING = "Warning";
|
2010-01-07 08:57:14 +01:00
|
|
|
/**
|
|
|
|
* {@code "WebSocket-Location"}
|
|
|
|
*/
|
|
|
|
public static final String WEBSOCKET_LOCATION = "WebSocket-Location";
|
|
|
|
/**
|
|
|
|
* {@code "WebSocket-Origin"}
|
|
|
|
*/
|
|
|
|
public static final String WEBSOCKET_ORIGIN = "WebSocket-Origin";
|
|
|
|
/**
|
|
|
|
* {@code "WebSocket-Protocol"}
|
|
|
|
*/
|
|
|
|
public static final String WEBSOCKET_PROTOCOL = "WebSocket-Protocol";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "WWW-Authenticate"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String WWW_AUTHENTICATE = "WWW-Authenticate";
|
2008-11-19 08:22:15 +01:00
|
|
|
|
2010-01-26 09:10:34 +01:00
|
|
|
private Names() {
|
2009-02-11 09:48:39 +01:00
|
|
|
super();
|
|
|
|
}
|
|
|
|
}
|
2008-11-19 08:22:15 +01:00
|
|
|
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
2009-06-19 16:17:02 +02:00
|
|
|
* Standard HTTP header values.
|
2009-06-19 16:15:20 +02:00
|
|
|
*
|
|
|
|
* @author The Netty Project (netty-dev@lists.jboss.org)
|
|
|
|
* @author Andy Taylor (andy.taylor@jboss.org)
|
|
|
|
* @version $Rev$, $Date$
|
2009-07-17 14:49:32 +02:00
|
|
|
*
|
|
|
|
* @apiviz.stereotype static
|
2009-06-19 16:15:20 +02:00
|
|
|
*/
|
2010-01-26 09:10:34 +01:00
|
|
|
public static final class Values {
|
2009-06-30 11:29:35 +02:00
|
|
|
/**
|
|
|
|
* {@code "base64"}
|
|
|
|
*/
|
|
|
|
public static final String BASE64 = "base64";
|
|
|
|
/**
|
|
|
|
* {@code "binary"}
|
|
|
|
*/
|
|
|
|
public static final String BINARY = "binary";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "bytes"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String BYTES = "bytes";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "charset"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String CHARSET = "charset";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "chunked"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String CHUNKED = "chunked";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "close"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String CLOSE = "close";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "compress"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String COMPRESS = "compress";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "100-continue"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String CONTINUE = "100-continue";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "deflate"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String DEFLATE = "deflate";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "gzip"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String GZIP = "gzip";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "identity"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String IDENTITY = "identity";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "keep-alive"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String KEEP_ALIVE = "keep-alive";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "max-age"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String MAX_AGE = "max-age";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "max-stale"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String MAX_STALE = "max-stale";
|
2010-01-25 05:22:45 +01:00
|
|
|
/**
|
|
|
|
* {@code "min-fresh"}
|
|
|
|
*/
|
|
|
|
public static final String MIN_FRESH = "min-fresh";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "must-revalidate"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String MUST_REVALIDATE = "must-revalidate";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "no-cache"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String NO_CACHE = "no-cache";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "no-store"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String NO_STORE = "no-store";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "no-transform"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String NO_TRANSFORM = "no-transform";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "none"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String NONE = "none";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "only-if-cached"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String ONLY_IF_CACHED = "only-if-cached";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "private"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String PRIVATE = "private";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "proxy-revalidate"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String PROXY_REVALIDATE = "proxy-revalidate";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "public"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String PUBLIC = "public";
|
2009-06-30 11:29:35 +02:00
|
|
|
/**
|
|
|
|
* {@code "quoted-printable"}
|
|
|
|
*/
|
|
|
|
public static final String QUOTED_PRINTABLE = "quoted-printable";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "s-maxage"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String S_MAXAGE = "s-maxage";
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* {@code "trailers"}
|
|
|
|
*/
|
2009-02-11 09:48:39 +01:00
|
|
|
public static final String TRAILERS = "trailers";
|
2010-01-08 09:29:37 +01:00
|
|
|
/**
|
|
|
|
* {@code "Upgrade"}
|
|
|
|
*/
|
|
|
|
public static final String UPGRADE = "Upgrade";
|
2010-01-07 08:57:14 +01:00
|
|
|
/**
|
|
|
|
* {@code "WebSocket"}
|
|
|
|
*/
|
|
|
|
public static final String WEBSOCKET = "WebSocket";
|
2008-11-19 08:22:15 +01:00
|
|
|
|
2010-01-26 09:10:34 +01:00
|
|
|
private Values() {
|
2009-02-11 09:48:39 +01:00
|
|
|
super();
|
|
|
|
}
|
2008-11-19 08:22:15 +01:00
|
|
|
}
|
|
|
|
|
2010-01-26 05:31:54 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the length of the content. Please note that this value is
|
|
|
|
* not retrieved from {@link HttpMessage#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
|
|
|
|
*/
|
|
|
|
public static long getContentLength(HttpMessage message) {
|
|
|
|
return getContentLength(message, 0L);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the length of the content. Please note that this value is
|
|
|
|
* not retrieved from {@link HttpMessage#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
|
|
|
|
*/
|
|
|
|
public static long getContentLength(HttpMessage message, long defaultValue) {
|
|
|
|
String contentLength = message.getHeader(Names.CONTENT_LENGTH);
|
|
|
|
if (contentLength != null) {
|
|
|
|
return Long.parseLong(contentLength);
|
|
|
|
}
|
|
|
|
return defaultValue;
|
|
|
|
}
|
|
|
|
|
2010-01-26 07:30:40 +01:00
|
|
|
// TODO Document me
|
|
|
|
|
2010-01-26 05:31:54 +01:00
|
|
|
public static void setContentLength(HttpMessage message, long value) {
|
|
|
|
message.setHeader(Names.CONTENT_LENGTH, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String getHost(HttpMessage message) {
|
|
|
|
return message.getHeader(Names.HOST);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String getHost(HttpMessage message, String defaultValue) {
|
|
|
|
String host = getHost(message);
|
|
|
|
if (host == null) {
|
|
|
|
return defaultValue;
|
|
|
|
}
|
|
|
|
return host;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setHost(HttpMessage message, String value) {
|
|
|
|
message.setHeader(Names.HOST, value);
|
|
|
|
}
|
|
|
|
|
2010-01-08 15:11:18 +01:00
|
|
|
private static final int BUCKET_SIZE = 17;
|
|
|
|
|
2010-01-08 09:29:37 +01:00
|
|
|
private static int hash(String name) {
|
|
|
|
int h = 0;
|
|
|
|
for (int i = name.length() - 1; i >= 0; i --) {
|
|
|
|
char c = name.charAt(i);
|
|
|
|
if (c >= 'A' && c <= 'Z') {
|
|
|
|
c += 32;
|
|
|
|
}
|
|
|
|
h = 31 * h + c;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (h > 0) {
|
|
|
|
return h;
|
|
|
|
} else if (h == Integer.MIN_VALUE) {
|
|
|
|
return Integer.MAX_VALUE;
|
|
|
|
} else {
|
|
|
|
return -h;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static boolean eq(String name1, String name2) {
|
|
|
|
int nameLen = name1.length();
|
|
|
|
if (nameLen != name2.length()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = nameLen - 1; i >= 0; i --) {
|
|
|
|
char c1 = name1.charAt(i);
|
|
|
|
char c2 = name2.charAt(i);
|
|
|
|
if (c1 != c2) {
|
|
|
|
if (c1 >= 'A' && c1 <= 'Z') {
|
|
|
|
c1 += 32;
|
|
|
|
}
|
|
|
|
if (c2 >= 'A' && c2 <= 'Z') {
|
|
|
|
c2 += 32;
|
|
|
|
}
|
|
|
|
if (c1 != c2) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-01-08 15:11:18 +01:00
|
|
|
private static int index(int hash) {
|
|
|
|
return hash % BUCKET_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
private final Entry[] entries = new Entry[BUCKET_SIZE];
|
2010-01-08 09:29:37 +01:00
|
|
|
private final Entry head = new Entry(-1, null, null);
|
|
|
|
|
|
|
|
HttpHeaders() {
|
|
|
|
head.before = head.after = head;
|
|
|
|
}
|
|
|
|
|
|
|
|
void validateHeaderName(String name) {
|
|
|
|
HttpCodecUtil.validateHeaderName(name);
|
|
|
|
}
|
|
|
|
|
2010-01-26 05:31:54 +01:00
|
|
|
void addHeader(final String name, final Object value) {
|
2010-01-08 09:29:37 +01:00
|
|
|
validateHeaderName(name);
|
2010-01-26 05:31:54 +01:00
|
|
|
String strVal = toString(value);
|
|
|
|
HttpCodecUtil.validateHeaderValue(strVal);
|
2010-01-08 09:29:37 +01:00
|
|
|
int h = hash(name);
|
|
|
|
int i = index(h);
|
2010-01-26 05:31:54 +01:00
|
|
|
addHeader0(h, i, name, strVal);
|
2010-01-08 09:29:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private void addHeader0(int h, int i, final String name, final String value) {
|
|
|
|
// Update the hash table.
|
|
|
|
Entry e = entries[i];
|
|
|
|
Entry newEntry;
|
|
|
|
if (e == null) {
|
|
|
|
entries[i] = newEntry = new Entry(h, name, value);
|
|
|
|
} else {
|
|
|
|
entries[i] = newEntry = new Entry(h, name, value);
|
|
|
|
newEntry.next = e;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the linked list.
|
|
|
|
newEntry.addBefore(head);
|
|
|
|
}
|
|
|
|
|
|
|
|
void removeHeader(final String name) {
|
2010-01-08 14:29:39 +01:00
|
|
|
if (name == null) {
|
|
|
|
throw new NullPointerException("name");
|
|
|
|
}
|
2010-01-08 09:29:37 +01:00
|
|
|
int h = hash(name);
|
|
|
|
int i = index(h);
|
|
|
|
removeHeader0(h, i, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void removeHeader0(int h, int i, String name) {
|
|
|
|
Entry e = entries[i];
|
|
|
|
if (e == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
if (e.hash == h && eq(name, e.key)) {
|
|
|
|
Entry next = e.next;
|
|
|
|
if (next != null) {
|
|
|
|
entries[i] = next;
|
|
|
|
e = next;
|
|
|
|
} else {
|
|
|
|
entries[i] = null;
|
2010-01-26 06:33:10 +01:00
|
|
|
e.remove();
|
2010-01-08 09:29:37 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
Entry next = e.next;
|
|
|
|
if (next == null) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (next.hash == h && eq(name, next.key)) {
|
|
|
|
e.next = next.next;
|
|
|
|
next.remove();
|
|
|
|
} else {
|
|
|
|
e = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-26 05:31:54 +01:00
|
|
|
void setHeader(final String name, final Object value) {
|
2010-01-08 09:29:37 +01:00
|
|
|
validateHeaderName(name);
|
2010-01-26 05:31:54 +01:00
|
|
|
String strVal = toString(value);
|
|
|
|
HttpCodecUtil.validateHeaderValue(strVal);
|
2010-01-08 09:29:37 +01:00
|
|
|
int h = hash(name);
|
|
|
|
int i = index(h);
|
|
|
|
removeHeader0(h, i, name);
|
2010-01-26 05:31:54 +01:00
|
|
|
addHeader0(h, i, name, strVal);
|
2010-01-08 09:29:37 +01:00
|
|
|
}
|
|
|
|
|
2010-01-26 05:31:54 +01:00
|
|
|
void setHeader(final String name, final Iterable<?> values) {
|
2010-01-08 09:29:37 +01:00
|
|
|
if (values == null) {
|
|
|
|
throw new NullPointerException("values");
|
|
|
|
}
|
|
|
|
|
2010-01-26 05:31:54 +01:00
|
|
|
validateHeaderName(name);
|
2010-01-08 09:29:37 +01:00
|
|
|
|
|
|
|
int h = hash(name);
|
|
|
|
int i = index(h);
|
|
|
|
|
|
|
|
removeHeader0(h, i, name);
|
2010-01-26 05:31:54 +01:00
|
|
|
for (Object v: values) {
|
2010-01-08 09:29:37 +01:00
|
|
|
if (v == null) {
|
|
|
|
break;
|
|
|
|
}
|
2010-01-26 05:31:54 +01:00
|
|
|
String strVal = toString(v);
|
|
|
|
HttpCodecUtil.validateHeaderValue(strVal);
|
|
|
|
addHeader0(h, i, name, strVal);
|
2010-01-08 09:29:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void clearHeaders() {
|
|
|
|
for (int i = 0; i < entries.length; i ++) {
|
|
|
|
entries[i] = null;
|
|
|
|
}
|
|
|
|
head.before = head.after = head;
|
|
|
|
}
|
|
|
|
|
|
|
|
String getHeader(final String name) {
|
2010-01-08 14:29:39 +01:00
|
|
|
if (name == null) {
|
|
|
|
throw new NullPointerException("name");
|
|
|
|
}
|
|
|
|
|
2010-01-08 09:29:37 +01:00
|
|
|
int h = hash(name);
|
|
|
|
int i = index(h);
|
|
|
|
Entry e = entries[i];
|
|
|
|
while (e != null) {
|
|
|
|
if (e.hash == h && eq(name, e.key)) {
|
|
|
|
return e.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
e = e.next;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
List<String> getHeaders(final String name) {
|
2010-01-08 14:29:39 +01:00
|
|
|
if (name == null) {
|
|
|
|
throw new NullPointerException("name");
|
|
|
|
}
|
|
|
|
|
2010-01-08 09:29:37 +01:00
|
|
|
LinkedList<String> values = new LinkedList<String>();
|
|
|
|
|
|
|
|
int h = hash(name);
|
|
|
|
int i = index(h);
|
|
|
|
Entry e = entries[i];
|
|
|
|
while (e != null) {
|
|
|
|
if (e.hash == h && eq(name, e.key)) {
|
|
|
|
values.addFirst(e.value);
|
|
|
|
}
|
|
|
|
e = e.next;
|
|
|
|
}
|
|
|
|
return values;
|
|
|
|
}
|
|
|
|
|
|
|
|
List<Map.Entry<String, String>> getHeaders() {
|
|
|
|
List<Map.Entry<String, String>> all =
|
|
|
|
new LinkedList<Map.Entry<String, String>>();
|
|
|
|
|
|
|
|
Entry e = head.after;
|
|
|
|
while (e != head) {
|
|
|
|
all.add(e);
|
|
|
|
e = e.after;
|
|
|
|
}
|
|
|
|
return all;
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean containsHeader(String name) {
|
|
|
|
return getHeader(name) != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
Set<String> getHeaderNames() {
|
|
|
|
Set<String> names =
|
|
|
|
new TreeSet<String>(CaseIgnoringComparator.INSTANCE);
|
|
|
|
|
|
|
|
Entry e = head.after;
|
|
|
|
while (e != head) {
|
|
|
|
names.add(e.key);
|
|
|
|
e = e.after;
|
|
|
|
}
|
|
|
|
return names;
|
|
|
|
}
|
|
|
|
|
2010-01-26 05:31:54 +01:00
|
|
|
private static String toString(Object value) {
|
|
|
|
if (value == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return value.toString();
|
|
|
|
}
|
|
|
|
|
2010-01-08 09:29:37 +01:00
|
|
|
private static final class Entry implements Map.Entry<String, String> {
|
|
|
|
final int hash;
|
|
|
|
final String key;
|
|
|
|
String value;
|
|
|
|
Entry next;
|
|
|
|
Entry before, after;
|
|
|
|
|
|
|
|
Entry(int hash, String key, String value) {
|
|
|
|
this.hash = hash;
|
|
|
|
this.key = key;
|
|
|
|
this.value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void remove() {
|
|
|
|
before.after = after;
|
|
|
|
after.before = before;
|
|
|
|
}
|
|
|
|
|
|
|
|
void addBefore(Entry e) {
|
|
|
|
after = e;
|
|
|
|
before = e.before;
|
|
|
|
before.after = this;
|
|
|
|
after.before = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getKey() {
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getValue() {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String setValue(String value) {
|
|
|
|
if (value == null) {
|
|
|
|
throw new NullPointerException("value");
|
|
|
|
}
|
|
|
|
HttpCodecUtil.validateHeaderValue(value);
|
|
|
|
String oldValue = this.value;
|
|
|
|
this.value = value;
|
|
|
|
return oldValue;
|
|
|
|
}
|
2008-11-19 08:22:15 +01:00
|
|
|
}
|
|
|
|
}
|