/*
* Copyright 2012 The Netty Project
*
* The Netty Project 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:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
package io.netty.handler.codec.http;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.handler.codec.DateFormatter;
import io.netty.handler.codec.Headers;
import io.netty.handler.codec.HeadersUtils;
import io.netty.util.AsciiString;
import io.netty.util.CharsetUtil;
import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import static io.netty.util.AsciiString.contentEquals;
import static io.netty.util.AsciiString.contentEqualsIgnoreCase;
import static io.netty.util.AsciiString.trim;
import static io.netty.util.internal.ObjectUtil.checkNotNull;
Provides the constants for the standard HTTP header names and values and commonly used utility methods that accesses an HttpMessage
. /**
* Provides the constants for the standard HTTP header names and values and
* commonly used utility methods that accesses an {@link HttpMessage}.
*/
public abstract class HttpHeaders implements Iterable<Map.Entry<String, String>> {
Deprecated: Use EmptyHttpHeaders.INSTANCE
. The instance is instantiated here to break the cyclic static initialization between EmptyHttpHeaders
and HttpHeaders
. The issue is that if someone accesses EmptyHttpHeaders.INSTANCE
before EMPTY_HEADERS
then EMPTY_HEADERS
will be null
.
/**
* @deprecated Use {@link EmptyHttpHeaders#INSTANCE}.
* <p>
* The instance is instantiated here to break the cyclic static initialization between {@link EmptyHttpHeaders} and
* {@link HttpHeaders}. The issue is that if someone accesses {@link EmptyHttpHeaders#INSTANCE} before
* {@link HttpHeaders#EMPTY_HEADERS} then {@link HttpHeaders#EMPTY_HEADERS} will be {@code null}.
*/
@Deprecated
public static final HttpHeaders EMPTY_HEADERS = EmptyHttpHeaders.instance();
Deprecated: Use HttpHeaderNames
instead. Standard HTTP header names.
/**
* @deprecated Use {@link HttpHeaderNames} instead.
*
* Standard HTTP header names.
*/
@Deprecated
public static final class Names {
"Accept"
/**
* {@code "Accept"}
*/
public static final String ACCEPT = "Accept";
"Accept-Charset"
/**
* {@code "Accept-Charset"}
*/
public static final String ACCEPT_CHARSET = "Accept-Charset";
"Accept-Encoding"
/**
* {@code "Accept-Encoding"}
*/
public static final String ACCEPT_ENCODING = "Accept-Encoding";
"Accept-Language"
/**
* {@code "Accept-Language"}
*/
public static final String ACCEPT_LANGUAGE = "Accept-Language";
"Accept-Ranges"
/**
* {@code "Accept-Ranges"}
*/
public static final String ACCEPT_RANGES = "Accept-Ranges";
"Accept-Patch"
/**
* {@code "Accept-Patch"}
*/
public static final String ACCEPT_PATCH = "Accept-Patch";
"Access-Control-Allow-Credentials"
/**
* {@code "Access-Control-Allow-Credentials"}
*/
public static final String ACCESS_CONTROL_ALLOW_CREDENTIALS = "Access-Control-Allow-Credentials";
"Access-Control-Allow-Headers"
/**
* {@code "Access-Control-Allow-Headers"}
*/
public static final String ACCESS_CONTROL_ALLOW_HEADERS = "Access-Control-Allow-Headers";
"Access-Control-Allow-Methods"
/**
* {@code "Access-Control-Allow-Methods"}
*/
public static final String ACCESS_CONTROL_ALLOW_METHODS = "Access-Control-Allow-Methods";
"Access-Control-Allow-Origin"
/**
* {@code "Access-Control-Allow-Origin"}
*/
public static final String ACCESS_CONTROL_ALLOW_ORIGIN = "Access-Control-Allow-Origin";
"Access-Control-Expose-Headers"
/**
* {@code "Access-Control-Expose-Headers"}
*/
public static final String ACCESS_CONTROL_EXPOSE_HEADERS = "Access-Control-Expose-Headers";
"Access-Control-Max-Age"
/**
* {@code "Access-Control-Max-Age"}
*/
public static final String ACCESS_CONTROL_MAX_AGE = "Access-Control-Max-Age";
"Access-Control-Request-Headers"
/**
* {@code "Access-Control-Request-Headers"}
*/
public static final String ACCESS_CONTROL_REQUEST_HEADERS = "Access-Control-Request-Headers";
"Access-Control-Request-Method"
/**
* {@code "Access-Control-Request-Method"}
*/
public static final String ACCESS_CONTROL_REQUEST_METHOD = "Access-Control-Request-Method";
"Age"
/**
* {@code "Age"}
*/
public static final String AGE = "Age";
"Allow"
/**
* {@code "Allow"}
*/
public static final String ALLOW = "Allow";
"Authorization"
/**
* {@code "Authorization"}
*/
public static final String AUTHORIZATION = "Authorization";
"Cache-Control"
/**
* {@code "Cache-Control"}
*/
public static final String CACHE_CONTROL = "Cache-Control";
"Connection"
/**
* {@code "Connection"}
*/
public static final String CONNECTION = "Connection";
"Content-Base"
/**
* {@code "Content-Base"}
*/
public static final String CONTENT_BASE = "Content-Base";
"Content-Encoding"
/**
* {@code "Content-Encoding"}
*/
public static final String CONTENT_ENCODING = "Content-Encoding";
"Content-Language"
/**
* {@code "Content-Language"}
*/
public static final String CONTENT_LANGUAGE = "Content-Language";
"Content-Length"
/**
* {@code "Content-Length"}
*/
public static final String CONTENT_LENGTH = "Content-Length";
"Content-Location"
/**
* {@code "Content-Location"}
*/
public static final String CONTENT_LOCATION = "Content-Location";
"Content-Transfer-Encoding"
/**
* {@code "Content-Transfer-Encoding"}
*/
public static final String CONTENT_TRANSFER_ENCODING = "Content-Transfer-Encoding";
"Content-MD5"
/**
* {@code "Content-MD5"}
*/
public static final String CONTENT_MD5 = "Content-MD5";
"Content-Range"
/**
* {@code "Content-Range"}
*/
public static final String CONTENT_RANGE = "Content-Range";
"Content-Type"
/**
* {@code "Content-Type"}
*/
public static final String CONTENT_TYPE = "Content-Type";
"Cookie"
/**
* {@code "Cookie"}
*/
public static final String COOKIE = "Cookie";
"Date"
/**
* {@code "Date"}
*/
public static final String DATE = "Date";
"ETag"
/**
* {@code "ETag"}
*/
public static final String ETAG = "ETag";
"Expect"
/**
* {@code "Expect"}
*/
public static final String EXPECT = "Expect";
"Expires"
/**
* {@code "Expires"}
*/
public static final String EXPIRES = "Expires";
"From"
/**
* {@code "From"}
*/
public static final String FROM = "From";
"Host"
/**
* {@code "Host"}
*/
public static final String HOST = "Host";
"If-Match"
/**
* {@code "If-Match"}
*/
public static final String IF_MATCH = "If-Match";
"If-Modified-Since"
/**
* {@code "If-Modified-Since"}
*/
public static final String IF_MODIFIED_SINCE = "If-Modified-Since";
"If-None-Match"
/**
* {@code "If-None-Match"}
*/
public static final String IF_NONE_MATCH = "If-None-Match";
"If-Range"
/**
* {@code "If-Range"}
*/
public static final String IF_RANGE = "If-Range";
"If-Unmodified-Since"
/**
* {@code "If-Unmodified-Since"}
*/
public static final String IF_UNMODIFIED_SINCE = "If-Unmodified-Since";
"Last-Modified"
/**
* {@code "Last-Modified"}
*/
public static final String LAST_MODIFIED = "Last-Modified";
"Location"
/**
* {@code "Location"}
*/
public static final String LOCATION = "Location";
"Max-Forwards"
/**
* {@code "Max-Forwards"}
*/
public static final String MAX_FORWARDS = "Max-Forwards";
"Origin"
/**
* {@code "Origin"}
*/
public static final String ORIGIN = "Origin";
"Pragma"
/**
* {@code "Pragma"}
*/
public static final String PRAGMA = "Pragma";
"Proxy-Authenticate"
/**
* {@code "Proxy-Authenticate"}
*/
public static final String PROXY_AUTHENTICATE = "Proxy-Authenticate";
"Proxy-Authorization"
/**
* {@code "Proxy-Authorization"}
*/
public static final String PROXY_AUTHORIZATION = "Proxy-Authorization";
"Range"
/**
* {@code "Range"}
*/
public static final String RANGE = "Range";
"Referer"
/**
* {@code "Referer"}
*/
public static final String REFERER = "Referer";
"Retry-After"
/**
* {@code "Retry-After"}
*/
public static final String RETRY_AFTER = "Retry-After";
"Sec-WebSocket-Key1"
/**
* {@code "Sec-WebSocket-Key1"}
*/
public static final String SEC_WEBSOCKET_KEY1 = "Sec-WebSocket-Key1";
"Sec-WebSocket-Key2"
/**
* {@code "Sec-WebSocket-Key2"}
*/
public static final String SEC_WEBSOCKET_KEY2 = "Sec-WebSocket-Key2";
"Sec-WebSocket-Location"
/**
* {@code "Sec-WebSocket-Location"}
*/
public static final String SEC_WEBSOCKET_LOCATION = "Sec-WebSocket-Location";
"Sec-WebSocket-Origin"
/**
* {@code "Sec-WebSocket-Origin"}
*/
public static final String SEC_WEBSOCKET_ORIGIN = "Sec-WebSocket-Origin";
"Sec-WebSocket-Protocol"
/**
* {@code "Sec-WebSocket-Protocol"}
*/
public static final String SEC_WEBSOCKET_PROTOCOL = "Sec-WebSocket-Protocol";
"Sec-WebSocket-Version"
/**
* {@code "Sec-WebSocket-Version"}
*/
public static final String SEC_WEBSOCKET_VERSION = "Sec-WebSocket-Version";
"Sec-WebSocket-Key"
/**
* {@code "Sec-WebSocket-Key"}
*/
public static final String SEC_WEBSOCKET_KEY = "Sec-WebSocket-Key";
"Sec-WebSocket-Accept"
/**
* {@code "Sec-WebSocket-Accept"}
*/
public static final String SEC_WEBSOCKET_ACCEPT = "Sec-WebSocket-Accept";
"Server"
/**
* {@code "Server"}
*/
public static final String SERVER = "Server";
"Set-Cookie"
/**
* {@code "Set-Cookie"}
*/
public static final String SET_COOKIE = "Set-Cookie";
"Set-Cookie2"
/**
* {@code "Set-Cookie2"}
*/
public static final String SET_COOKIE2 = "Set-Cookie2";
"TE"
/**
* {@code "TE"}
*/
public static final String TE = "TE";
"Trailer"
/**
* {@code "Trailer"}
*/
public static final String TRAILER = "Trailer";
"Transfer-Encoding"
/**
* {@code "Transfer-Encoding"}
*/
public static final String TRANSFER_ENCODING = "Transfer-Encoding";
"Upgrade"
/**
* {@code "Upgrade"}
*/
public static final String UPGRADE = "Upgrade";
"User-Agent"
/**
* {@code "User-Agent"}
*/
public static final String USER_AGENT = "User-Agent";
"Vary"
/**
* {@code "Vary"}
*/
public static final String VARY = "Vary";
"Via"
/**
* {@code "Via"}
*/
public static final String VIA = "Via";
"Warning"
/**
* {@code "Warning"}
*/
public static final String WARNING = "Warning";
"WebSocket-Location"
/**
* {@code "WebSocket-Location"}
*/
public static final String WEBSOCKET_LOCATION = "WebSocket-Location";
"WebSocket-Origin"
/**
* {@code "WebSocket-Origin"}
*/
public static final String WEBSOCKET_ORIGIN = "WebSocket-Origin";
"WebSocket-Protocol"
/**
* {@code "WebSocket-Protocol"}
*/
public static final String WEBSOCKET_PROTOCOL = "WebSocket-Protocol";
"WWW-Authenticate"
/**
* {@code "WWW-Authenticate"}
*/
public static final String WWW_AUTHENTICATE = "WWW-Authenticate";
private Names() {
}
}
Deprecated: Use HttpHeaderValues
instead. Standard HTTP header values.
/**
* @deprecated Use {@link HttpHeaderValues} instead.
*
* Standard HTTP header values.
*/
@Deprecated
public static final class Values {
"application/json"
/**
* {@code "application/json"}
*/
public static final String APPLICATION_JSON = "application/json";
"application/x-www-form-urlencoded"
/**
* {@code "application/x-www-form-urlencoded"}
*/
public static final String APPLICATION_X_WWW_FORM_URLENCODED =
"application/x-www-form-urlencoded";
"base64"
/**
* {@code "base64"}
*/
public static final String BASE64 = "base64";
"binary"
/**
* {@code "binary"}
*/
public static final String BINARY = "binary";
"boundary"
/**
* {@code "boundary"}
*/
public static final String BOUNDARY = "boundary";
"bytes"
/**
* {@code "bytes"}
*/
public static final String BYTES = "bytes";
"charset"
/**
* {@code "charset"}
*/
public static final String CHARSET = "charset";
"chunked"
/**
* {@code "chunked"}
*/
public static final String CHUNKED = "chunked";
"close"
/**
* {@code "close"}
*/
public static final String CLOSE = "close";
"compress"
/**
* {@code "compress"}
*/
public static final String COMPRESS = "compress";
"100-continue"
/**
* {@code "100-continue"}
*/
public static final String CONTINUE = "100-continue";
"deflate"
/**
* {@code "deflate"}
*/
public static final String DEFLATE = "deflate";
"gzip"
/**
* {@code "gzip"}
*/
public static final String GZIP = "gzip";
"gzip,deflate"
/**
* {@code "gzip,deflate"}
*/
public static final String GZIP_DEFLATE = "gzip,deflate";
"identity"
/**
* {@code "identity"}
*/
public static final String IDENTITY = "identity";
"keep-alive"
/**
* {@code "keep-alive"}
*/
public static final String KEEP_ALIVE = "keep-alive";
"max-age"
/**
* {@code "max-age"}
*/
public static final String MAX_AGE = "max-age";
"max-stale"
/**
* {@code "max-stale"}
*/
public static final String MAX_STALE = "max-stale";
"min-fresh"
/**
* {@code "min-fresh"}
*/
public static final String MIN_FRESH = "min-fresh";
"multipart/form-data"
/**
* {@code "multipart/form-data"}
*/
public static final String MULTIPART_FORM_DATA = "multipart/form-data";
"must-revalidate"
/**
* {@code "must-revalidate"}
*/
public static final String MUST_REVALIDATE = "must-revalidate";
"no-cache"
/**
* {@code "no-cache"}
*/
public static final String NO_CACHE = "no-cache";
"no-store"
/**
* {@code "no-store"}
*/
public static final String NO_STORE = "no-store";
"no-transform"
/**
* {@code "no-transform"}
*/
public static final String NO_TRANSFORM = "no-transform";
"none"
/**
* {@code "none"}
*/
public static final String NONE = "none";
"only-if-cached"
/**
* {@code "only-if-cached"}
*/
public static final String ONLY_IF_CACHED = "only-if-cached";
"private"
/**
* {@code "private"}
*/
public static final String PRIVATE = "private";
"proxy-revalidate"
/**
* {@code "proxy-revalidate"}
*/
public static final String PROXY_REVALIDATE = "proxy-revalidate";
"public"
/**
* {@code "public"}
*/
public static final String PUBLIC = "public";
"quoted-printable"
/**
* {@code "quoted-printable"}
*/
public static final String QUOTED_PRINTABLE = "quoted-printable";
"s-maxage"
/**
* {@code "s-maxage"}
*/
public static final String S_MAXAGE = "s-maxage";
"trailers"
/**
* {@code "trailers"}
*/
public static final String TRAILERS = "trailers";
"Upgrade"
/**
* {@code "Upgrade"}
*/
public static final String UPGRADE = "Upgrade";
"WebSocket"
/**
* {@code "WebSocket"}
*/
public static final String WEBSOCKET = "WebSocket";
private Values() {
}
}
Deprecated: Use HttpUtil.isKeepAlive(HttpMessage)
instead. Returns true
if and only if the connection can remain open and thus 'kept alive'. This methods respects the value of the "Connection"
header first and then the return value of HttpVersion.isKeepAliveDefault()
.
/**
* @deprecated Use {@link HttpUtil#isKeepAlive(HttpMessage)} instead.
*
* Returns {@code true} if and only if the connection can remain open and
* thus 'kept alive'. This methods respects the value of the
* {@code "Connection"} header first and then the return value of
* {@link HttpVersion#isKeepAliveDefault()}.
*/
@Deprecated
public static boolean isKeepAlive(HttpMessage message) {
return HttpUtil.isKeepAlive(message);
}
Deprecated: Use HttpUtil.setKeepAlive(HttpMessage, boolean)
instead. Sets the value of the "Connection"
header depending on the protocol version of the specified message. This getMethod sets or removes the "Connection"
header depending on what the default keep alive mode of the message's protocol version is, as specified by HttpVersion.isKeepAliveDefault()
.
- If the connection is kept alive by default:
- set to
"close"
if keepAlive
is false
.
- remove otherwise.
- If the connection is closed by default:
- set to
"keep-alive"
if keepAlive
is true
.
- remove otherwise.
/**
* @deprecated Use {@link HttpUtil#setKeepAlive(HttpMessage, boolean)} instead.
*
* Sets the value of the {@code "Connection"} header depending on the
* protocol version of the specified message. This getMethod sets or removes
* the {@code "Connection"} header depending on what the default keep alive
* mode of the message's protocol version is, as specified by
* {@link HttpVersion#isKeepAliveDefault()}.
* <ul>
* <li>If the connection is kept alive by default:
* <ul>
* <li>set to {@code "close"} if {@code keepAlive} is {@code false}.</li>
* <li>remove otherwise.</li>
* </ul></li>
* <li>If the connection is closed by default:
* <ul>
* <li>set to {@code "keep-alive"} if {@code keepAlive} is {@code true}.</li>
* <li>remove otherwise.</li>
* </ul></li>
* </ul>
*/
@Deprecated
public static void setKeepAlive(HttpMessage message, boolean keepAlive) {
HttpUtil.setKeepAlive(message, keepAlive);
}
Deprecated: Use get(CharSequence)
instead.
/**
* @deprecated Use {@link #get(CharSequence)} instead.
*/
@Deprecated
public static String getHeader(HttpMessage message, String name) {
return message.headers().get(name);
}
Deprecated: Use get(CharSequence)
instead. 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. Returns: the header value or null
if there is no such header
/**
* @deprecated Use {@link #get(CharSequence)} instead.
*
* 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
*/
@Deprecated
public static String getHeader(HttpMessage message, CharSequence name) {
return message.headers().get(name);
}
See Also: Deprecated: Use get(CharSequence, String)
instead.
/**
* @deprecated Use {@link #get(CharSequence, String)} instead.
*
* @see #getHeader(HttpMessage, CharSequence, String)
*/
@Deprecated
public static String getHeader(HttpMessage message, String name, String defaultValue) {
return message.headers().get(name, defaultValue);
}
Deprecated: Use get(CharSequence, String)
instead. 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. Returns: the header value or the defaultValue
if there is no such header
/**
* @deprecated Use {@link #get(CharSequence, String)} instead.
*
* 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 the {@code defaultValue} if there is no such
* header
*/
@Deprecated
public static String getHeader(HttpMessage message, CharSequence name, String defaultValue) {
return message.headers().get(name, defaultValue);
}
See Also: Deprecated: Use set(CharSequence, Object)
instead.
/**
* @deprecated Use {@link #set(CharSequence, Object)} instead.
*
* @see #setHeader(HttpMessage, CharSequence, Object)
*/
@Deprecated
public static void setHeader(HttpMessage message, String name, Object value) {
message.headers().set(name, value);
}
Deprecated: Use set(CharSequence, Object)
instead. 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. If the specified value is not a String
, it is converted into a String
by Object.toString()
, except for Date
and Calendar
which are formatted to the date format defined in RFC2616.
/**
* @deprecated Use {@link #set(CharSequence, Object)} instead.
*
* 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.
* If the specified value is not a {@link String}, it is converted into a
* {@link String} by {@link Object#toString()}, except for {@link Date}
* and {@link Calendar} which are formatted to the date format defined in
* <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1">RFC2616</a>.
*/
@Deprecated
public static void setHeader(HttpMessage message, CharSequence name, Object value) {
message.headers().set(name, value);
}
See Also: Deprecated: Use set(CharSequence, Iterable<?>)
instead.
/**
* @deprecated Use {@link #set(CharSequence, Iterable)} instead.
*
* @see #setHeader(HttpMessage, CharSequence, Iterable)
*/
@Deprecated
public static void setHeader(HttpMessage message, String name, Iterable<?> values) {
message.headers().set(name, values);
}
Deprecated: Use set(CharSequence, Iterable<?>)
instead. 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. This getMethod can be represented approximately as the following code: removeHeader(message, name);
for (Object v: values) {
if (v == null) {
break;
}
addHeader(message, name, v);
}
/**
* @deprecated Use {@link #set(CharSequence, Iterable)} instead.
*
* 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.
* This getMethod can be represented approximately as the following code:
* <pre>
* removeHeader(message, name);
* for (Object v: values) {
* if (v == null) {
* break;
* }
* addHeader(message, name, v);
* }
* </pre>
*/
@Deprecated
public static void setHeader(HttpMessage message, CharSequence name, Iterable<?> values) {
message.headers().set(name, values);
}
See Also: Deprecated: Use add(CharSequence, Object)
instead.
/**
* @deprecated Use {@link #add(CharSequence, Object)} instead.
*
* @see #addHeader(HttpMessage, CharSequence, Object)
*/
@Deprecated
public static void addHeader(HttpMessage message, String name, Object value) {
message.headers().add(name, value);
}
Deprecated: Use add(CharSequence, Object)
instead. Adds a new header with the specified name and value. If the specified value is not a String
, it is converted into a String
by Object.toString()
, except for Date
and Calendar
which are formatted to the date format defined in RFC2616.
/**
* @deprecated Use {@link #add(CharSequence, Object)} instead.
*
* Adds a new header with the specified name and value.
* If the specified value is not a {@link String}, it is converted into a
* {@link String} by {@link Object#toString()}, except for {@link Date}
* and {@link Calendar} which are formatted to the date format defined in
* <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1">RFC2616</a>.
*/
@Deprecated
public static void addHeader(HttpMessage message, CharSequence name, Object value) {
message.headers().add(name, value);
}
See Also: Deprecated: Use remove(CharSequence)
instead.
/**
* @deprecated Use {@link #remove(CharSequence)} instead.
*
* @see #removeHeader(HttpMessage, CharSequence)
*/
@Deprecated
public static void removeHeader(HttpMessage message, String name) {
message.headers().remove(name);
}
Deprecated: Use remove(CharSequence)
instead. Removes the header with the specified name.
/**
* @deprecated Use {@link #remove(CharSequence)} instead.
*
* Removes the header with the specified name.
*/
@Deprecated
public static void removeHeader(HttpMessage message, CharSequence name) {
message.headers().remove(name);
}
Deprecated: Use clear()
instead. Removes all headers from the specified message.
/**
* @deprecated Use {@link #clear()} instead.
*
* Removes all headers from the specified message.
*/
@Deprecated
public static void clearHeaders(HttpMessage message) {
message.headers().clear();
}
See Also: Deprecated: Use getInt(CharSequence)
instead.
/**
* @deprecated Use {@link #getInt(CharSequence)} instead.
*
* @see #getIntHeader(HttpMessage, CharSequence)
*/
@Deprecated
public static int getIntHeader(HttpMessage message, String name) {
return getIntHeader(message, (CharSequence) name);
}
Throws: - NumberFormatException –
if there is no such header or the header value is not a number
Deprecated: Use getInt(CharSequence)
instead. Returns the integer 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. Returns: the header value
/**
* @deprecated Use {@link #getInt(CharSequence)} instead.
*
* Returns the integer 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
* @throws NumberFormatException
* if there is no such header or the header value is not a number
*/
@Deprecated
public static int getIntHeader(HttpMessage message, CharSequence name) {
String value = message.headers().get(name);
if (value == null) {
throw new NumberFormatException("header not found: " + name);
}
return Integer.parseInt(value);
}
See Also: Deprecated: Use getInt(CharSequence, int)
instead.
/**
* @deprecated Use {@link #getInt(CharSequence, int)} instead.
*
* @see #getIntHeader(HttpMessage, CharSequence, int)
*/
@Deprecated
public static int getIntHeader(HttpMessage message, String name, int defaultValue) {
return message.headers().getInt(name, defaultValue);
}
Deprecated: Use getInt(CharSequence, int)
instead. Returns the integer 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. Returns: the header value or the defaultValue
if there is no such header or the header value is not a number
/**
* @deprecated Use {@link #getInt(CharSequence, int)} instead.
*
* Returns the integer 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 the {@code defaultValue} if there is no such
* header or the header value is not a number
*/
@Deprecated
public static int getIntHeader(HttpMessage message, CharSequence name, int defaultValue) {
return message.headers().getInt(name, defaultValue);
}
See Also: Deprecated: Use setInt(CharSequence, int)
instead.
/**
* @deprecated Use {@link #setInt(CharSequence, int)} instead.
*
* @see #setIntHeader(HttpMessage, CharSequence, int)
*/
@Deprecated
public static void setIntHeader(HttpMessage message, String name, int value) {
message.headers().setInt(name, value);
}
Deprecated: Use setInt(CharSequence, int)
instead. Sets a new integer header with the specified name and value. If there is an existing header with the same name, the existing header is removed.
/**
* @deprecated Use {@link #setInt(CharSequence, int)} instead.
*
* Sets a new integer header with the specified name and value. If there
* is an existing header with the same name, the existing header is removed.
*/
@Deprecated
public static void setIntHeader(HttpMessage message, CharSequence name, int value) {
message.headers().setInt(name, value);
}
See Also: Deprecated: Use set(CharSequence, Iterable<?>)
instead.
/**
* @deprecated Use {@link #set(CharSequence, Iterable)} instead.
*
* @see #setIntHeader(HttpMessage, CharSequence, Iterable)
*/
@Deprecated
public static void setIntHeader(HttpMessage message, String name, Iterable<Integer> values) {
message.headers().set(name, values);
}
Deprecated: Use set(CharSequence, Iterable<?>)
instead. Sets a new integer header with the specified name and values. If there is an existing header with the same name, the existing header is removed.
/**
* @deprecated Use {@link #set(CharSequence, Iterable)} instead.
*
* Sets a new integer header with the specified name and values. If there
* is an existing header with the same name, the existing header is removed.
*/
@Deprecated
public static void setIntHeader(HttpMessage message, CharSequence name, Iterable<Integer> values) {
message.headers().set(name, values);
}
See Also: Deprecated: Use add(CharSequence, Iterable<?>)
instead.
/**
* @deprecated Use {@link #add(CharSequence, Iterable)} instead.
*
* @see #addIntHeader(HttpMessage, CharSequence, int)
*/
@Deprecated
public static void addIntHeader(HttpMessage message, String name, int value) {
message.headers().add(name, value);
}
Deprecated: Use addInt(CharSequence, int)
instead. Adds a new integer header with the specified name and value.
/**
* @deprecated Use {@link #addInt(CharSequence, int)} instead.
*
* Adds a new integer header with the specified name and value.
*/
@Deprecated
public static void addIntHeader(HttpMessage message, CharSequence name, int value) {
message.headers().addInt(name, value);
}
See Also: Deprecated: Use getTimeMillis(CharSequence)
instead.
/**
* @deprecated Use {@link #getTimeMillis(CharSequence)} instead.
*
* @see #getDateHeader(HttpMessage, CharSequence)
*/
@Deprecated
public static Date getDateHeader(HttpMessage message, String name) throws ParseException {
return getDateHeader(message, (CharSequence) name);
}
Throws: - ParseException –
if there is no such header or the header value is not a formatted date
Deprecated: Use getTimeMillis(CharSequence)
instead. Returns the date 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. Returns: the header value
/**
* @deprecated Use {@link #getTimeMillis(CharSequence)} instead.
*
* Returns the date 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
* @throws ParseException
* if there is no such header or the header value is not a formatted date
*/
@Deprecated
public static Date getDateHeader(HttpMessage message, CharSequence name) throws ParseException {
String value = message.headers().get(name);
if (value == null) {
throw new ParseException("header not found: " + name, 0);
}
Date date = DateFormatter.parseHttpDate(value);
if (date == null) {
throw new ParseException("header can't be parsed into a Date: " + value, 0);
}
return date;
}
See Also: Deprecated: Use getTimeMillis(CharSequence, long)
instead.
/**
* @deprecated Use {@link #getTimeMillis(CharSequence, long)} instead.
*
* @see #getDateHeader(HttpMessage, CharSequence, Date)
*/
@Deprecated
public static Date getDateHeader(HttpMessage message, String name, Date defaultValue) {
return getDateHeader(message, (CharSequence) name, defaultValue);
}
Deprecated: Use getTimeMillis(CharSequence, long)
instead. Returns the date 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. Returns: the header value or the defaultValue
if there is no such header or the header value is not a formatted date
/**
* @deprecated Use {@link #getTimeMillis(CharSequence, long)} instead.
*
* Returns the date 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 the {@code defaultValue} if there is no such
* header or the header value is not a formatted date
*/
@Deprecated
public static Date getDateHeader(HttpMessage message, CharSequence name, Date defaultValue) {
final String value = getHeader(message, name);
Date date = DateFormatter.parseHttpDate(value);
return date != null ? date : defaultValue;
}
See Also: Deprecated: Use set(CharSequence, Object)
instead.
/**
* @deprecated Use {@link #set(CharSequence, Object)} instead.
*
* @see #setDateHeader(HttpMessage, CharSequence, Date)
*/
@Deprecated
public static void setDateHeader(HttpMessage message, String name, Date value) {
setDateHeader(message, (CharSequence) name, value);
}
Deprecated: Use set(CharSequence, Object)
instead. Sets a new date header with the specified name and value. If there is an existing header with the same name, the existing header is removed. The specified value is formatted as defined in RFC2616
/**
* @deprecated Use {@link #set(CharSequence, Object)} instead.
*
* Sets a new date header with the specified name and value. If there
* is an existing header with the same name, the existing header is removed.
* The specified value is formatted as defined in
* <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1">RFC2616</a>
*/
@Deprecated
public static void setDateHeader(HttpMessage message, CharSequence name, Date value) {
if (value != null) {
message.headers().set(name, DateFormatter.format(value));
} else {
message.headers().set(name, null);
}
}
See Also: Deprecated: Use set(CharSequence, Iterable<?>)
instead.
/**
* @deprecated Use {@link #set(CharSequence, Iterable)} instead.
*
* @see #setDateHeader(HttpMessage, CharSequence, Iterable)
*/
@Deprecated
public static void setDateHeader(HttpMessage message, String name, Iterable<Date> values) {
message.headers().set(name, values);
}
Deprecated: Use set(CharSequence, Iterable<?>)
instead. Sets a new date header with the specified name and values. If there is an existing header with the same name, the existing header is removed. The specified values are formatted as defined in RFC2616
/**
* @deprecated Use {@link #set(CharSequence, Iterable)} instead.
*
* Sets a new date header with the specified name and values. If there
* is an existing header with the same name, the existing header is removed.
* The specified values are formatted as defined in
* <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1">RFC2616</a>
*/
@Deprecated
public static void setDateHeader(HttpMessage message, CharSequence name, Iterable<Date> values) {
message.headers().set(name, values);
}
See Also: Deprecated: Use add(CharSequence, Object)
instead.
/**
* @deprecated Use {@link #add(CharSequence, Object)} instead.
*
* @see #addDateHeader(HttpMessage, CharSequence, Date)
*/
@Deprecated
public static void addDateHeader(HttpMessage message, String name, Date value) {
message.headers().add(name, value);
}
Deprecated: Use add(CharSequence, Object)
instead. Adds a new date header with the specified name and value. The specified value is formatted as defined in RFC2616
/**
* @deprecated Use {@link #add(CharSequence, Object)} instead.
*
* Adds a new date header with the specified name and value. The specified
* value is formatted as defined in
* <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1">RFC2616</a>
*/
@Deprecated
public static void addDateHeader(HttpMessage message, CharSequence name, Date value) {
message.headers().add(name, value);
}
Throws: - NumberFormatException – if the message does not have the
"Content-Length"
header or its value is not a number
Deprecated: Use HttpUtil.getContentLength(HttpMessage)
instead. Returns the length of the content. Please note that this value is not retrieved from ByteBufHolder.content()
but from the "Content-Length"
header, and thus they are independent from each other. Returns: the content length
/**
* @deprecated Use {@link HttpUtil#getContentLength(HttpMessage)} instead.
*
* Returns the length of the content. Please note that this value is
* not retrieved from {@link HttpContent#content()} but from the
* {@code "Content-Length"} header, and thus they are independent from each
* other.
*
* @return the content length
*
* @throws NumberFormatException
* if the message does not have the {@code "Content-Length"} header
* or its value is not a number
*/
@Deprecated
public static long getContentLength(HttpMessage message) {
return HttpUtil.getContentLength(message);
}
Deprecated: Use HttpUtil.getContentLength(HttpMessage, long)
instead. Returns the length of the content. Please note that this value is not retrieved from ByteBufHolder.content()
but from the "Content-Length"
header, and thus they are independent from each other. Returns: the content length or defaultValue
if this message does not have the "Content-Length"
header or its value is not a number
/**
* @deprecated Use {@link HttpUtil#getContentLength(HttpMessage, long)} instead.
*
* Returns the length of the content. Please note that this value is
* not retrieved from {@link HttpContent#content()} 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 or its value is not
* a number
*/
@Deprecated
public static long getContentLength(HttpMessage message, long defaultValue) {
return HttpUtil.getContentLength(message, defaultValue);
}
Deprecated: Use HttpUtil.setContentLength(HttpMessage, long)
instead.
/**
* @deprecated Use {@link HttpUtil#setContentLength(HttpMessage, long)} instead.
*/
@Deprecated
public static void setContentLength(HttpMessage message, long length) {
HttpUtil.setContentLength(message, length);
}
Deprecated: Use get(CharSequence)
instead. Returns the value of the "Host"
header.
/**
* @deprecated Use {@link #get(CharSequence)} instead.
*
* Returns the value of the {@code "Host"} header.
*/
@Deprecated
public static String getHost(HttpMessage message) {
return message.headers().get(HttpHeaderNames.HOST);
}
Deprecated: Use get(CharSequence, String)
instead. Returns the value of the "Host"
header. If there is no such header, the defaultValue
is returned.
/**
* @deprecated Use {@link #get(CharSequence, String)} instead.
*
* Returns the value of the {@code "Host"} header. If there is no such
* header, the {@code defaultValue} is returned.
*/
@Deprecated
public static String getHost(HttpMessage message, String defaultValue) {
return message.headers().get(HttpHeaderNames.HOST, defaultValue);
}
See Also: Deprecated: Use set(CharSequence, Object)
instead.
/**
* @deprecated Use {@link #set(CharSequence, Object)} instead.
*
* @see #setHost(HttpMessage, CharSequence)
*/
@Deprecated
public static void setHost(HttpMessage message, String value) {
message.headers().set(HttpHeaderNames.HOST, value);
}
Deprecated: Use set(CharSequence, Object)
instead. Sets the "Host"
header.
/**
* @deprecated Use {@link #set(CharSequence, Object)} instead.
*
* Sets the {@code "Host"} header.
*/
@Deprecated
public static void setHost(HttpMessage message, CharSequence value) {
message.headers().set(HttpHeaderNames.HOST, value);
}
Throws: - ParseException –
if there is no such header or the header value is not a formatted date
Deprecated: Use getTimeMillis(CharSequence)
instead. Returns the value of the "Date"
header.
/**
* @deprecated Use {@link #getTimeMillis(CharSequence)} instead.
*
* Returns the value of the {@code "Date"} header.
*
* @throws ParseException
* if there is no such header or the header value is not a formatted date
*/
@Deprecated
public static Date getDate(HttpMessage message) throws ParseException {
return getDateHeader(message, HttpHeaderNames.DATE);
}
Deprecated: Use getTimeMillis(CharSequence, long)
instead. Returns the value of the "Date"
header. If there is no such header or the header is not a formatted date, the defaultValue
is returned.
/**
* @deprecated Use {@link #getTimeMillis(CharSequence, long)} instead.
*
* Returns the value of the {@code "Date"} header. If there is no such
* header or the header is not a formatted date, the {@code defaultValue}
* is returned.
*/
@Deprecated
public static Date getDate(HttpMessage message, Date defaultValue) {
return getDateHeader(message, HttpHeaderNames.DATE, defaultValue);
}
Deprecated: Use set(CharSequence, Object)
instead. Sets the "Date"
header.
/**
* @deprecated Use {@link #set(CharSequence, Object)} instead.
*
* Sets the {@code "Date"} header.
*/
@Deprecated
public static void setDate(HttpMessage message, Date value) {
message.headers().set(HttpHeaderNames.DATE, value);
}
Deprecated: Use HttpUtil.is100ContinueExpected(HttpMessage)
instead. Returns true
if and only if the specified message contains the "Expect: 100-continue"
header.
/**
* @deprecated Use {@link HttpUtil#is100ContinueExpected(HttpMessage)} instead.
*
* Returns {@code true} if and only if the specified message contains the
* {@code "Expect: 100-continue"} header.
*/
@Deprecated
public static boolean is100ContinueExpected(HttpMessage message) {
return HttpUtil.is100ContinueExpected(message);
}
Deprecated: Use HttpUtil.set100ContinueExpected(HttpMessage, boolean)
instead. Sets the "Expect: 100-continue"
header to the specified message. If there is any existing "Expect"
header, they are replaced with the new one.
/**
* @deprecated Use {@link HttpUtil#set100ContinueExpected(HttpMessage, boolean)} instead.
*
* Sets the {@code "Expect: 100-continue"} header to the specified message.
* If there is any existing {@code "Expect"} header, they are replaced with
* the new one.
*/
@Deprecated
public static void set100ContinueExpected(HttpMessage message) {
HttpUtil.set100ContinueExpected(message, true);
}
Deprecated: Use HttpUtil.set100ContinueExpected(HttpMessage, boolean)
instead. Sets or removes the "Expect: 100-continue"
header to / from the specified message. If set
is true
, the "Expect: 100-continue"
header is set and all other previous "Expect"
headers are removed. Otherwise, all "Expect"
headers are removed completely.
/**
* @deprecated Use {@link HttpUtil#set100ContinueExpected(HttpMessage, boolean)} instead.
*
* Sets or removes the {@code "Expect: 100-continue"} header to / from the
* specified message. If {@code set} is {@code true},
* the {@code "Expect: 100-continue"} header is set and all other previous
* {@code "Expect"} headers are removed. Otherwise, all {@code "Expect"}
* headers are removed completely.
*/
@Deprecated
public static void set100ContinueExpected(HttpMessage message, boolean set) {
HttpUtil.set100ContinueExpected(message, set);
}
Params: - message – The message to check
Deprecated: Use HttpUtil.isTransferEncodingChunked(HttpMessage)
instead. Checks to see if the transfer encoding in a specified HttpMessage
is chunked Returns: True if transfer encoding is chunked, otherwise false
/**
* @deprecated Use {@link HttpUtil#isTransferEncodingChunked(HttpMessage)} instead.
*
* Checks to see if the transfer encoding in a specified {@link HttpMessage} is chunked
*
* @param message The message to check
* @return True if transfer encoding is chunked, otherwise false
*/
@Deprecated
public static boolean isTransferEncodingChunked(HttpMessage message) {
return HttpUtil.isTransferEncodingChunked(message);
}
Deprecated: Use HttpUtil.setTransferEncodingChunked(HttpMessage, boolean)
instead.
/**
* @deprecated Use {@link HttpUtil#setTransferEncodingChunked(HttpMessage, boolean)} instead.
*/
@Deprecated
public static void removeTransferEncodingChunked(HttpMessage m) {
HttpUtil.setTransferEncodingChunked(m, false);
}
Deprecated: Use HttpUtil.setTransferEncodingChunked(HttpMessage, boolean)
instead.
/**
* @deprecated Use {@link HttpUtil#setTransferEncodingChunked(HttpMessage, boolean)} instead.
*/
@Deprecated
public static void setTransferEncodingChunked(HttpMessage m) {
HttpUtil.setTransferEncodingChunked(m, true);
}
Deprecated: Use HttpUtil.isContentLengthSet(HttpMessage)
instead.
/**
* @deprecated Use {@link HttpUtil#isContentLengthSet(HttpMessage)} instead.
*/
@Deprecated
public static boolean isContentLengthSet(HttpMessage m) {
return HttpUtil.isContentLengthSet(m);
}
Deprecated: Use AsciiString.contentEqualsIgnoreCase(CharSequence, CharSequence)
instead.
/**
* @deprecated Use {@link AsciiString#contentEqualsIgnoreCase(CharSequence, CharSequence)} instead.
*/
@Deprecated
public static boolean equalsIgnoreCase(CharSequence name1, CharSequence name2) {
return contentEqualsIgnoreCase(name1, name2);
}
@Deprecated
public static void encodeAscii(CharSequence seq, ByteBuf buf) {
if (seq instanceof AsciiString) {
ByteBufUtil.copy((AsciiString) seq, 0, buf, seq.length());
} else {
buf.writeCharSequence(seq, CharsetUtil.US_ASCII);
}
}
Deprecated: Use AsciiString
instead. Create a new CharSequence
which is optimized for reuse as HttpHeaders
name or value. So if you have a Header name or value that you want to reuse you should make use of this.
/**
* @deprecated Use {@link AsciiString} instead.
* <p>
* Create a new {@link CharSequence} which is optimized for reuse as {@link HttpHeaders} name or value.
* So if you have a Header name or value that you want to reuse you should make use of this.
*/
@Deprecated
public static CharSequence newEntity(String name) {
return new AsciiString(name);
}
protected HttpHeaders() { }
See Also: - get(CharSequence)
/**
* @see #get(CharSequence)
*/
public abstract String get(String name);
Returns the value of a header with the specified name. If there are
more than one values for the specified name, the first value is returned.
Params: - name – The name of the header to search
See Also: Returns: The first header value or null
if there is no such header
/**
* Returns the value of a header with the specified name. If there are
* more than one values for the specified name, the first value is returned.
*
* @param name The name of the header to search
* @return The first header value or {@code null} if there is no such header
* @see #getAsString(CharSequence)
*/
public String get(CharSequence name) {
return get(name.toString());
}
Returns the value of a header with the specified name. If there are
more than one values for the specified name, the first value is returned.
Params: - name – The name of the header to search
Returns: The first header value or defaultValue
if there is no such header
/**
* Returns the value of a header with the specified name. If there are
* more than one values for the specified name, the first value is returned.
*
* @param name The name of the header to search
* @return The first header value or {@code defaultValue} if there is no such header
*/
public String get(CharSequence name, String defaultValue) {
String value = get(name);
if (value == null) {
return defaultValue;
}
return value;
}
Returns the integer value of a header with the specified name. If there are more than one values for the
specified name, the first value is returned.
Params: - name – the name of the header to search
Returns: the first header value if the header is found and its value is an integer. null
if there's no such header or its value is not an integer.
/**
* Returns the integer value of a header with the specified name. If there are more than one values for the
* specified name, the first value is returned.
*
* @param name the name of the header to search
* @return the first header value if the header is found and its value is an integer. {@code null} if there's no
* such header or its value is not an integer.
*/
public abstract Integer getInt(CharSequence name);
Returns the integer value of a header with the specified name. If there are more than one values for the
specified name, the first value is returned.
Params: - name – the name of the header to search
- defaultValue – the default value
Returns: the first header value if the header is found and its value is an integer. defaultValue
if there's no such header or its value is not an integer.
/**
* Returns the integer value of a header with the specified name. If there are more than one values for the
* specified name, the first value is returned.
*
* @param name the name of the header to search
* @param defaultValue the default value
* @return the first header value if the header is found and its value is an integer. {@code defaultValue} if
* there's no such header or its value is not an integer.
*/
public abstract int getInt(CharSequence name, int defaultValue);
Returns the short value of a header with the specified name. If there are more than one values for the
specified name, the first value is returned.
Params: - name – the name of the header to search
Returns: the first header value if the header is found and its value is a short. null
if there's no such header or its value is not a short.
/**
* Returns the short value of a header with the specified name. If there are more than one values for the
* specified name, the first value is returned.
*
* @param name the name of the header to search
* @return the first header value if the header is found and its value is a short. {@code null} if there's no
* such header or its value is not a short.
*/
public abstract Short getShort(CharSequence name);
Returns the short value of a header with the specified name. If there are more than one values for the
specified name, the first value is returned.
Params: - name – the name of the header to search
- defaultValue – the default value
Returns: the first header value if the header is found and its value is a short. defaultValue
if there's no such header or its value is not a short.
/**
* Returns the short value of a header with the specified name. If there are more than one values for the
* specified name, the first value is returned.
*
* @param name the name of the header to search
* @param defaultValue the default value
* @return the first header value if the header is found and its value is a short. {@code defaultValue} if
* there's no such header or its value is not a short.
*/
public abstract short getShort(CharSequence name, short defaultValue);
Returns the date value of a header with the specified name. If there are more than one values for the
specified name, the first value is returned.
Params: - name – the name of the header to search
Returns: the first header value if the header is found and its value is a date. null
if there's no such header or its value is not a date.
/**
* Returns the date value of a header with the specified name. If there are more than one values for the
* specified name, the first value is returned.
*
* @param name the name of the header to search
* @return the first header value if the header is found and its value is a date. {@code null} if there's no
* such header or its value is not a date.
*/
public abstract Long getTimeMillis(CharSequence name);
Returns the date value of a header with the specified name. If there are more than one values for the
specified name, the first value is returned.
Params: - name – the name of the header to search
- defaultValue – the default value
Returns: the first header value if the header is found and its value is a date. defaultValue
if there's no such header or its value is not a date.
/**
* Returns the date value of a header with the specified name. If there are more than one values for the
* specified name, the first value is returned.
*
* @param name the name of the header to search
* @param defaultValue the default value
* @return the first header value if the header is found and its value is a date. {@code defaultValue} if
* there's no such header or its value is not a date.
*/
public abstract long getTimeMillis(CharSequence name, long defaultValue);
See Also: - getAll(CharSequence)
/**
* @see #getAll(CharSequence)
*/
public abstract List<String> getAll(String name);
Returns the values of headers with the specified name
Params: - name – The name of the headers to search
See Also: Returns: A List
of header values which will be empty if no values are found
/**
* Returns the values of headers with the specified name
*
* @param name The name of the headers to search
* @return A {@link List} of header values which will be empty if no values
* are found
* @see #getAllAsString(CharSequence)
*/
public List<String> getAll(CharSequence name) {
return getAll(name.toString());
}
Returns a new List
that contains all headers in this object. Note that modifying the returned List
will not affect the state of this object. If you intend to enumerate over the header entries only, use iterator()
instead, which has much less overhead. See Also:
/**
* Returns a new {@link List} that contains all headers in this object. Note that modifying the
* returned {@link List} will not affect the state of this object. If you intend to enumerate over the header
* entries only, use {@link #iterator()} instead, which has much less overhead.
* @see #iteratorCharSequence()
*/
public abstract List<Map.Entry<String, String>> entries();
See Also: - contains(CharSequence)
/**
* @see #contains(CharSequence)
*/
public abstract boolean contains(String name);
Deprecated: It is preferred to use iteratorCharSequence()
unless you need String
. If String
is required then use iteratorAsString()
.
/**
* @deprecated It is preferred to use {@link #iteratorCharSequence()} unless you need {@link String}.
* If {@link String} is required then use {@link #iteratorAsString()}.
*/
@Deprecated
@Override
public abstract Iterator<Entry<String, String>> iterator();
Returns: Iterator over the name/value header pairs.
/**
* @return Iterator over the name/value header pairs.
*/
public abstract Iterator<Entry<CharSequence, CharSequence>> iteratorCharSequence();
Equivalent to getAll(String)
but it is possible that no intermediate list is generated. Params: - name – the name of the header to retrieve
Returns: an Iterator
of header values corresponding to name
.
/**
* Equivalent to {@link #getAll(String)} but it is possible that no intermediate list is generated.
* @param name the name of the header to retrieve
* @return an {@link Iterator} of header values corresponding to {@code name}.
*/
public Iterator<String> valueStringIterator(CharSequence name) {
return getAll(name).iterator();
}
Equivalent to getAll(String)
but it is possible that no intermediate list is generated. Params: - name – the name of the header to retrieve
Returns: an Iterator
of header values corresponding to name
.
/**
* Equivalent to {@link #getAll(String)} but it is possible that no intermediate list is generated.
* @param name the name of the header to retrieve
* @return an {@link Iterator} of header values corresponding to {@code name}.
*/
public Iterator<? extends CharSequence> valueCharSequenceIterator(CharSequence name) {
return valueStringIterator(name);
}
Checks to see if there is a header with the specified name
Params: - name – The name of the header to search for
Returns: True if at least one header is found
/**
* Checks to see if there is a header with the specified name
*
* @param name The name of the header to search for
* @return True if at least one header is found
*/
public boolean contains(CharSequence name) {
return contains(name.toString());
}
Checks if no header exists.
/**
* Checks if no header exists.
*/
public abstract boolean isEmpty();
Returns the number of headers in this object.
/**
* Returns the number of headers in this object.
*/
public abstract int size();
Returns a new Set
that contains the names of all headers in this object. Note that modifying the returned Set
will not affect the state of this object. If you intend to enumerate over the header entries only, use iterator()
instead, which has much less overhead. /**
* Returns a new {@link Set} that contains the names of all headers in this object. Note that modifying the
* returned {@link Set} will not affect the state of this object. If you intend to enumerate over the header
* entries only, use {@link #iterator()} instead, which has much less overhead.
*/
public abstract Set<String> names();
See Also: - add(CharSequence, Object)
/**
* @see #add(CharSequence, Object)
*/
public abstract HttpHeaders add(String name, Object value);
Adds a new header with the specified name and value. If the specified value is not a String
, it is converted into a String
by Object.toString()
, except in the cases of Date
and Calendar
, which are formatted to the date format defined in RFC2616.
Params: - name – The name of the header being added
- value – The value of the header being added
Returns: this
/**
* Adds a new header with the specified name and value.
*
* If the specified value is not a {@link String}, it is converted
* into a {@link String} by {@link Object#toString()}, except in the cases
* of {@link Date} and {@link Calendar}, which are formatted to the date
* format defined in <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1">RFC2616</a>.
*
* @param name The name of the header being added
* @param value The value of the header being added
*
* @return {@code this}
*/
public HttpHeaders add(CharSequence name, Object value) {
return add(name.toString(), value);
}
See Also: - add(CharSequence, Iterable)
/**
* @see #add(CharSequence, Iterable)
*/
public abstract HttpHeaders add(String name, Iterable<?> values);
Adds a new header with the specified name and values.
This getMethod can be represented approximately as the following code:
for (Object v: values) {
if (v == null) {
break;
}
headers.add(name, v);
}
Params: - name – The name of the headers being set
- values – The values of the headers being set
Returns: this
/**
* Adds a new header with the specified name and values.
*
* This getMethod can be represented approximately as the following code:
* <pre>
* for (Object v: values) {
* if (v == null) {
* break;
* }
* headers.add(name, v);
* }
* </pre>
*
* @param name The name of the headers being set
* @param values The values of the headers being set
* @return {@code this}
*/
public HttpHeaders add(CharSequence name, Iterable<?> values) {
return add(name.toString(), values);
}
Adds all header entries of the specified headers
. Returns: this
/**
* Adds all header entries of the specified {@code headers}.
*
* @return {@code this}
*/
public HttpHeaders add(HttpHeaders headers) {
if (headers == null) {
throw new NullPointerException("headers");
}
for (Map.Entry<String, String> e: headers) {
add(e.getKey(), e.getValue());
}
return this;
}
Add the name
to value
. Params: - name – The name to modify
- value – The value
Returns: this
/**
* Add the {@code name} to {@code value}.
* @param name The name to modify
* @param value The value
* @return {@code this}
*/
public abstract HttpHeaders addInt(CharSequence name, int value);
Add the name
to value
. Params: - name – The name to modify
- value – The value
Returns: this
/**
* Add the {@code name} to {@code value}.
* @param name The name to modify
* @param value The value
* @return {@code this}
*/
public abstract HttpHeaders addShort(CharSequence name, short value);
See Also: - set(CharSequence, Object)
/**
* @see #set(CharSequence, Object)
*/
public abstract HttpHeaders set(String name, Object value);
Sets a header with the specified name and value. If there is an existing header with the same name, it is removed. If the specified value is not a String
, it is converted into a String
by Object.toString()
, except for Date
and Calendar
, which are formatted to the date format defined in RFC2616.
Params: - name – The name of the header being set
- value – The value of the header being set
Returns: this
/**
* Sets a header with the specified name and value.
*
* If there is an existing header with the same name, it is removed.
* If the specified value is not a {@link String}, it is converted into a
* {@link String} by {@link Object#toString()}, except for {@link Date}
* and {@link Calendar}, which are formatted to the date format defined in
* <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1">RFC2616</a>.
*
* @param name The name of the header being set
* @param value The value of the header being set
* @return {@code this}
*/
public HttpHeaders set(CharSequence name, Object value) {
return set(name.toString(), value);
}
See Also: - set(CharSequence, Iterable)
/**
* @see #set(CharSequence, Iterable)
*/
public abstract HttpHeaders set(String name, Iterable<?> values);
Sets a header with the specified name and values.
If there is an existing header with the same name, it is removed.
This getMethod can be represented approximately as the following code:
headers.remove(name);
for (Object v: values) {
if (v == null) {
break;
}
headers.add(name, v);
}
Params: - name – The name of the headers being set
- values – The values of the headers being set
Returns: this
/**
* Sets a header with the specified name and values.
*
* If there is an existing header with the same name, it is removed.
* This getMethod can be represented approximately as the following code:
* <pre>
* headers.remove(name);
* for (Object v: values) {
* if (v == null) {
* break;
* }
* headers.add(name, v);
* }
* </pre>
*
* @param name The name of the headers being set
* @param values The values of the headers being set
* @return {@code this}
*/
public HttpHeaders set(CharSequence name, Iterable<?> values) {
return set(name.toString(), values);
}
Cleans the current header entries and copies all header entries of the specified headers
. Returns: this
/**
* Cleans the current header entries and copies all header entries of the specified {@code headers}.
*
* @return {@code this}
*/
public HttpHeaders set(HttpHeaders headers) {
checkNotNull(headers, "headers");
clear();
if (headers.isEmpty()) {
return this;
}
for (Entry<String, String> entry : headers) {
add(entry.getKey(), entry.getValue());
}
return this;
}
Retains all current headers but calls set(String, Object)
for each entry in headers
Params: - headers – The headers used to
set(String, Object)
values in this instance
Returns: this
/**
* Retains all current headers but calls {@link #set(String, Object)} for each entry in {@code headers}
*
* @param headers The headers used to {@link #set(String, Object)} values in this instance
* @return {@code this}
*/
public HttpHeaders setAll(HttpHeaders headers) {
checkNotNull(headers, "headers");
if (headers.isEmpty()) {
return this;
}
for (Entry<String, String> entry : headers) {
set(entry.getKey(), entry.getValue());
}
return this;
}
Set the name
to value
. This will remove all previous values associated with name
. Params: - name – The name to modify
- value – The value
Returns: this
/**
* Set the {@code name} to {@code value}. This will remove all previous values associated with {@code name}.
* @param name The name to modify
* @param value The value
* @return {@code this}
*/
public abstract HttpHeaders setInt(CharSequence name, int value);
Set the name
to value
. This will remove all previous values associated with name
. Params: - name – The name to modify
- value – The value
Returns: this
/**
* Set the {@code name} to {@code value}. This will remove all previous values associated with {@code name}.
* @param name The name to modify
* @param value The value
* @return {@code this}
*/
public abstract HttpHeaders setShort(CharSequence name, short value);
See Also: - remove(CharSequence)
/**
* @see #remove(CharSequence)
*/
public abstract HttpHeaders remove(String name);
Removes the header with the specified name.
Params: - name – The name of the header to remove
Returns: this
/**
* Removes the header with the specified name.
*
* @param name The name of the header to remove
* @return {@code this}
*/
public HttpHeaders remove(CharSequence name) {
return remove(name.toString());
}
Removes all headers from this HttpMessage
. Returns: this
/**
* Removes all headers from this {@link HttpMessage}.
*
* @return {@code this}
*/
public abstract HttpHeaders clear();
See Also: - contains(CharSequence, CharSequence, boolean)
/**
* @see #contains(CharSequence, CharSequence, boolean)
*/
public boolean contains(String name, String value, boolean ignoreCase) {
Iterator<String> valueIterator = valueStringIterator(name);
if (ignoreCase) {
while (valueIterator.hasNext()) {
if (valueIterator.next().equalsIgnoreCase(value)) {
return true;
}
}
} else {
while (valueIterator.hasNext()) {
if (valueIterator.next().equals(value)) {
return true;
}
}
}
return false;
}
Returns true
if a header with the name
and value
exists, false
otherwise. This also handles multiple values that are separated with a ,
. If ignoreCase
is true
then a case insensitive compare is done on the value.
Params: - name – the name of the header to find
- value – the value of the header to find
- ignoreCase –
true
then a case insensitive compare is run to compare values. otherwise a case sensitive compare is run to compare values.
/**
* Returns {@code true} if a header with the {@code name} and {@code value} exists, {@code false} otherwise.
* This also handles multiple values that are separated with a {@code ,}.
* <p>
* If {@code ignoreCase} is {@code true} then a case insensitive compare is done on the value.
* @param name the name of the header to find
* @param value the value of the header to find
* @param ignoreCase {@code true} then a case insensitive compare is run to compare values.
* otherwise a case sensitive compare is run to compare values.
*/
public boolean containsValue(CharSequence name, CharSequence value, boolean ignoreCase) {
Iterator<? extends CharSequence> itr = valueCharSequenceIterator(name);
while (itr.hasNext()) {
if (containsCommaSeparatedTrimmed(itr.next(), value, ignoreCase)) {
return true;
}
}
return false;
}
private static boolean containsCommaSeparatedTrimmed(CharSequence rawNext, CharSequence expected,
boolean ignoreCase) {
int begin = 0;
int end;
if (ignoreCase) {
if ((end = AsciiString.indexOf(rawNext, ',', begin)) == -1) {
if (contentEqualsIgnoreCase(trim(rawNext), expected)) {
return true;
}
} else {
do {
if (contentEqualsIgnoreCase(trim(rawNext.subSequence(begin, end)), expected)) {
return true;
}
begin = end + 1;
} while ((end = AsciiString.indexOf(rawNext, ',', begin)) != -1);
if (begin < rawNext.length()) {
if (contentEqualsIgnoreCase(trim(rawNext.subSequence(begin, rawNext.length())), expected)) {
return true;
}
}
}
} else {
if ((end = AsciiString.indexOf(rawNext, ',', begin)) == -1) {
if (contentEquals(trim(rawNext), expected)) {
return true;
}
} else {
do {
if (contentEquals(trim(rawNext.subSequence(begin, end)), expected)) {
return true;
}
begin = end + 1;
} while ((end = AsciiString.indexOf(rawNext, ',', begin)) != -1);
if (begin < rawNext.length()) {
if (contentEquals(trim(rawNext.subSequence(begin, rawNext.length())), expected)) {
return true;
}
}
}
}
return false;
}
Headers.get(Object)
and convert the result to a String
. Params: - name – the name of the header to retrieve
Returns: the first header value if the header is found. null
if there's no such header.
/**
* {@link Headers#get(Object)} and convert the result to a {@link String}.
* @param name the name of the header to retrieve
* @return the first header value if the header is found. {@code null} if there's no such header.
*/
public final String getAsString(CharSequence name) {
return get(name);
}
Params: - name – the name of the header to retrieve
Returns: a List
of header values or an empty List
if no values are found.
/**
* {@link Headers#getAll(Object)} and convert each element of {@link List} to a {@link String}.
* @param name the name of the header to retrieve
* @return a {@link List} of header values or an empty {@link List} if no values are found.
*/
public final List<String> getAllAsString(CharSequence name) {
return getAll(name);
}
/**
* {@link Iterator} that converts each {@link Entry}'s key and value to a {@link String}.
*/
public final Iterator<Entry<String, String>> iteratorAsString() {
return iterator();
}
Returns true
if a header with the name
and value
exists, false
otherwise. If ignoreCase
is true
then a case insensitive compare is done on the value.
Params: - name – the name of the header to find
- value – the value of the header to find
- ignoreCase –
true
then a case insensitive compare is run to compare values. otherwise a case sensitive compare is run to compare values.
/**
* Returns {@code true} if a header with the {@code name} and {@code value} exists, {@code false} otherwise.
* <p>
* If {@code ignoreCase} is {@code true} then a case insensitive compare is done on the value.
* @param name the name of the header to find
* @param value the value of the header to find
* @param ignoreCase {@code true} then a case insensitive compare is run to compare values.
* otherwise a case sensitive compare is run to compare values.
*/
public boolean contains(CharSequence name, CharSequence value, boolean ignoreCase) {
return contains(name.toString(), value.toString(), ignoreCase);
}
@Override
public String toString() {
return HeadersUtils.toString(getClass(), iteratorCharSequence(), size());
}
Returns a deap copy of the passed in HttpHeaders
. /**
* Returns a deap copy of the passed in {@link HttpHeaders}.
*/
public HttpHeaders copy() {
return new DefaultHttpHeaders().set(this);
}
}