-
public interface HttpHeadersAn injectable interface that provides access to HTTP header information. All methods throwIllegalStateExceptionif called outside the scope of a request (e.g. from a provider constructor).- Since:
- 1.0
- See Also:
Context
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringACCEPTstatic java.lang.StringACCEPT_CHARSETstatic java.lang.StringACCEPT_ENCODINGstatic java.lang.StringACCEPT_LANGUAGEstatic java.lang.StringALLOWstatic java.lang.StringAUTHORIZATIONstatic java.lang.StringCACHE_CONTROLstatic java.lang.StringCONTENT_DISPOSITIONSee IETF RFC-2183.static java.lang.StringCONTENT_ENCODINGstatic java.lang.StringCONTENT_IDSee IETF RFC-2392.static java.lang.StringCONTENT_LANGUAGEstatic java.lang.StringCONTENT_LENGTHstatic java.lang.StringCONTENT_LOCATIONstatic java.lang.StringCONTENT_TYPEstatic java.lang.StringCOOKIESee IETF RFC 2109.static java.lang.StringDATEstatic java.lang.StringETAGstatic java.lang.StringEXPECTstatic java.lang.StringEXPIRESstatic java.lang.StringHOSTstatic java.lang.StringIF_MATCHstatic java.lang.StringIF_MODIFIED_SINCEstatic java.lang.StringIF_NONE_MATCHstatic java.lang.StringIF_UNMODIFIED_SINCEstatic java.lang.StringLAST_EVENT_ID_HEADER"Last-Event-ID"HTTP request header name as defined by SSE specification.static java.lang.StringLAST_MODIFIEDstatic java.lang.StringLINKstatic java.lang.StringLOCATIONstatic java.lang.StringRETRY_AFTERstatic java.lang.StringSET_COOKIESee IETF RFC 2109.static java.lang.StringUSER_AGENTstatic java.lang.StringVARYstatic java.lang.StringWWW_AUTHENTICATE
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description booleancontainsHeaderString(java.lang.String name, java.lang.String valueSeparatorRegex, java.util.function.Predicate<java.lang.String> valuePredicate)Checks whether a header with a specific name and value (or item of the token-separated value list) exists.default booleancontainsHeaderString(java.lang.String name, java.util.function.Predicate<java.lang.String> valuePredicate)Checks whether a header with a specific name and value (or item of the comma-separated value list) exists.java.util.List<java.util.Locale>getAcceptableLanguages()Get a list of languages that are acceptable for the response.java.util.List<MediaType>getAcceptableMediaTypes()Get a list of media types that are acceptable for the response.java.util.Map<java.lang.String,Cookie>getCookies()Get any cookies that accompanied the request.java.util.DategetDate()Get message date.java.lang.StringgetHeaderString(java.lang.String name)Get a HTTP header as a single string value.java.util.LocalegetLanguage()Get the language of the request entity.intgetLength()Get Content-Length value.MediaTypegetMediaType()Get the media type of the request entity.java.util.List<java.lang.String>getRequestHeader(java.lang.String name)Get the values of a HTTP request header if the header exists on the current request.MultivaluedMap<java.lang.String,java.lang.String>getRequestHeaders()Get the values of HTTP request headers.
-
-
-
Field Detail
-
ACCEPT
static final java.lang.String ACCEPT
- See Also:
- Constant Field Values
-
ACCEPT_CHARSET
static final java.lang.String ACCEPT_CHARSET
- See Also:
- Constant Field Values
-
ACCEPT_ENCODING
static final java.lang.String ACCEPT_ENCODING
- See Also:
- Constant Field Values
-
ACCEPT_LANGUAGE
static final java.lang.String ACCEPT_LANGUAGE
- See Also:
- Constant Field Values
-
ALLOW
static final java.lang.String ALLOW
- See Also:
- Constant Field Values
-
AUTHORIZATION
static final java.lang.String AUTHORIZATION
- See Also:
- Constant Field Values
-
CACHE_CONTROL
static final java.lang.String CACHE_CONTROL
- See Also:
- Constant Field Values
-
CONTENT_DISPOSITION
static final java.lang.String CONTENT_DISPOSITION
See IETF RFC-2183.- See Also:
- Constant Field Values
-
CONTENT_ENCODING
static final java.lang.String CONTENT_ENCODING
- See Also:
- Constant Field Values
-
CONTENT_ID
static final java.lang.String CONTENT_ID
See IETF RFC-2392.- See Also:
- Constant Field Values
-
CONTENT_LANGUAGE
static final java.lang.String CONTENT_LANGUAGE
- See Also:
- Constant Field Values
-
CONTENT_LENGTH
static final java.lang.String CONTENT_LENGTH
- See Also:
- Constant Field Values
-
CONTENT_LOCATION
static final java.lang.String CONTENT_LOCATION
- See Also:
- Constant Field Values
-
CONTENT_TYPE
static final java.lang.String CONTENT_TYPE
- See Also:
- Constant Field Values
-
DATE
static final java.lang.String DATE
- See Also:
- Constant Field Values
-
ETAG
static final java.lang.String ETAG
- See Also:
- Constant Field Values
-
EXPECT
static final java.lang.String EXPECT
- See Also:
- Constant Field Values
-
EXPIRES
static final java.lang.String EXPIRES
- See Also:
- Constant Field Values
-
HOST
static final java.lang.String HOST
- See Also:
- Constant Field Values
-
IF_MATCH
static final java.lang.String IF_MATCH
- See Also:
- Constant Field Values
-
IF_MODIFIED_SINCE
static final java.lang.String IF_MODIFIED_SINCE
- See Also:
- Constant Field Values
-
IF_NONE_MATCH
static final java.lang.String IF_NONE_MATCH
- See Also:
- Constant Field Values
-
IF_UNMODIFIED_SINCE
static final java.lang.String IF_UNMODIFIED_SINCE
- See Also:
- Constant Field Values
-
LAST_MODIFIED
static final java.lang.String LAST_MODIFIED
- See Also:
- Constant Field Values
-
LOCATION
static final java.lang.String LOCATION
- See Also:
- Constant Field Values
-
LINK
static final java.lang.String LINK
- See Also:
- Constant Field Values
-
RETRY_AFTER
static final java.lang.String RETRY_AFTER
- See Also:
- Constant Field Values
-
USER_AGENT
static final java.lang.String USER_AGENT
- See Also:
- Constant Field Values
-
VARY
static final java.lang.String VARY
- See Also:
- Constant Field Values
-
WWW_AUTHENTICATE
static final java.lang.String WWW_AUTHENTICATE
- See Also:
- Constant Field Values
-
COOKIE
static final java.lang.String COOKIE
See IETF RFC 2109.- See Also:
- Constant Field Values
-
SET_COOKIE
static final java.lang.String SET_COOKIE
See IETF RFC 2109.- See Also:
- Constant Field Values
-
LAST_EVENT_ID_HEADER
static final java.lang.String LAST_EVENT_ID_HEADER
"Last-Event-ID"HTTP request header name as defined by SSE specification.- Since:
- 2.1
- See Also:
- Constant Field Values
-
-
Method Detail
-
getRequestHeader
java.util.List<java.lang.String> getRequestHeader(java.lang.String name)
Get the values of a HTTP request header if the header exists on the current request. The returned value will be a read-only List if the specified header exists ornullif it does not. This is a shortcut forgetRequestHeaders().get(name).- Parameters:
name- the header name, case insensitive.- Returns:
- a read-only list of header values if the specified header exists, otherwise
null. - Throws:
java.lang.IllegalStateException- if called outside the scope of a request.
-
getHeaderString
java.lang.String getHeaderString(java.lang.String name)
Get a HTTP header as a single string value.
Each single non-string header value is converted to String using aRuntimeDelegate.HeaderDelegateif one is available viaRuntimeDelegate.createHeaderDelegate(java.lang.Class)for the header value class or using itstoStringmethod if a header delegate is not available.- Parameters:
name- the HTTP header.- Returns:
- the HTTP header value. If the HTTP header is not present then
nullis returned. If the HTTP header is present but has no value then the empty string is returned. If the HTTP header is present more than once then the values of joined together and separated by a ',' character. - Since:
- 2.0
- See Also:
getRequestHeader(java.lang.String)
-
containsHeaderString
boolean containsHeaderString(java.lang.String name, java.lang.String valueSeparatorRegex, java.util.function.Predicate<java.lang.String> valuePredicate)Checks whether a header with a specific name and value (or item of the token-separated value list) exists. Each single non-string header value is converted to String using aRuntimeDelegate.HeaderDelegateif one is available viaRuntimeDelegate.createHeaderDelegate(java.lang.Class)for the header value class or using itstoStringmethod if a header delegate is not available.For example:
containsHeaderString("cache-control", ",", "no-store"::equalsIgnoreCase)will returntrueif aCache-Controlheader exists that has the valueno-store, the valueNo-Storeor the valueMax-Age, NO-STORE, no-transform, butfalsewhen it has the valueno-store;no-transform(missing comma), or the valueno - store(whitespace within value).- Parameters:
name- the message header.valueSeparatorRegex- Regular expression that separates the header value into single values.nulldoes not split.valuePredicate- value must fulfil this predicate.- Returns:
trueif and only if a header with the given name exists, having either a whitespace-trimmed value matching the predicate, or having at least one whitespace-trimmed single value in a token-separated list of single values.- Since:
- 4.0
- See Also:
getRequestHeaders(),getHeaderString(String)
-
containsHeaderString
default boolean containsHeaderString(java.lang.String name, java.util.function.Predicate<java.lang.String> valuePredicate)Checks whether a header with a specific name and value (or item of the comma-separated value list) exists. Each single non-string header value is converted to String using aRuntimeDelegate.HeaderDelegateif one is available viaRuntimeDelegate.createHeaderDelegate(java.lang.Class)for the header value class or using itstoStringmethod if a header delegate is not available.For example:
containsHeaderString("cache-control", "no-store"::equalsIgnoreCase)will returntrueif aCache-Controlheader exists that has the valueno-store, the valueNo-Storeor the valueMax-Age, NO-STORE, no-transform, butfalsewhen it has the valueno-store;no-transform(missing comma), or the valueno - store(whitespace within value).- Parameters:
name- the message header.valuePredicate- value must fulfil this predicate.- Returns:
trueif and only if a header with the given name exists, having either a whitespace-trimmed value matching the predicate, or having at least one whitespace-trimmed single value in a comma-separated list of single values.- Since:
- 4.0
- See Also:
getRequestHeaders(),getHeaderString(String)
-
getRequestHeaders
MultivaluedMap<java.lang.String,java.lang.String> getRequestHeaders()
Get the values of HTTP request headers. The returned Map is case-insensitive wrt. keys and is read-only. The method never returnsnull.- Returns:
- a read-only map of header names and values.
- Throws:
java.lang.IllegalStateException- if called outside the scope of a request.
-
getAcceptableMediaTypes
java.util.List<MediaType> getAcceptableMediaTypes()
Get a list of media types that are acceptable for the response.
If no acceptable media types are specified, a read-only list containing a singlewildcard media typeinstance is returned.- Returns:
- a read-only list of requested response media types sorted according to their q-value, with highest preference first.
- Throws:
java.lang.IllegalStateException- if called outside the scope of a request.
-
getAcceptableLanguages
java.util.List<java.util.Locale> getAcceptableLanguages()
Get a list of languages that are acceptable for the response.
If no acceptable languages are specified, a read-only list containing a single wildcardLocaleinstance (with language field set to "*") is returned.- Returns:
- a read-only list of acceptable languages sorted according to their q-value, with highest preference first.
- Throws:
java.lang.IllegalStateException- if called outside the scope of a request.
-
getMediaType
MediaType getMediaType()
Get the media type of the request entity.- Returns:
- the media type or
nullif there is no request entity. - Throws:
java.lang.IllegalStateException- if called outside the scope of a request.
-
getLanguage
java.util.Locale getLanguage()
Get the language of the request entity.- Returns:
- the language of the entity or
nullif not specified. - Throws:
java.lang.IllegalStateException- if called outside the scope of a request.
-
getCookies
java.util.Map<java.lang.String,Cookie> getCookies()
Get any cookies that accompanied the request.- Returns:
- a read-only map of cookie name (String) to Cookie.
- Throws:
java.lang.IllegalStateException- if called outside the scope of a request
-
getDate
java.util.Date getDate()
Get message date.- Returns:
- the message date, otherwise
nullif not present. - Since:
- 2.0
-
getLength
int getLength()
Get Content-Length value.- Returns:
- Content-Length as integer if present and valid number. In other cases returns -1.
- Since:
- 2.0
-
-