Top Description Fields Methods
jakarta.ws.rs.core

public Interface HttpHeaders

Imports
java.util.Date, .List, .Locale, .Map, java.util.function.Predicate

An injectable interface that provides access to HTTP header information. All methods throw java.lang.IllegalStateException if called outside the scope of a request (e.g. from a provider constructor).
Authors
Paul Sandoz, Marc Hadley
Since
1.0
See Also
Context

Field Summary

Modifier and TypeField and Description
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
LAST_EVENT_ID_HEADER

"Last-Event-ID" HTTP request header name as defined by SSE specification.

public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if 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.
containsHeaderString
(String
the message header.
name
,
String
Regular expression that separates the header value into single values. null does not split.
valueSeparatorRegex
,
Predicate<String>
value must fulfil this predicate.
valuePredicate
)

Checks whether a header with a specific name and value (or item of the token-separated value list) exists.

public default boolean

Returns:

true if 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.
containsHeaderString
(String
the message header.
name
,
Predicate<String>
value must fulfil this predicate.
valuePredicate
)

Checks whether a header with a specific name and value (or item of the comma-separated value list) exists.

public List<Locale>

Returns:

a read-only list of acceptable languages sorted according to their q-value, with highest preference first.
getAcceptableLanguages
()

Get a list of languages that are acceptable for the response.

public List<MediaType>

Returns:

a read-only list of requested response media types sorted according to their q-value, with highest preference first.
getAcceptableMediaTypes
()

Get a list of media types that are acceptable for the response.

public Map<String, Cookie>

Returns:

a read-only map of cookie name (String) to Cookie.
getCookies
()

Get any cookies that accompanied the request.

public Date

Returns:

the message date, otherwise null if not present.
getDate
()

Get message date.

public String

Returns:

the HTTP header value. If the HTTP header is not present then null is 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.
getHeaderString
(String
the HTTP header.
name
)

Get a HTTP header as a single string value.

public Locale

Returns:

the language of the entity or null if not specified.
getLanguage
()

Get the language of the request entity.

public int

Returns:

Content-Length as integer if present and valid number. In other cases returns -1.
getLength
()

Get Content-Length value.

public MediaType

Returns:

the media type or null if there is no request entity.
getMediaType
()

Get the media type of the request entity.

public List<String>

Returns:

a read-only list of header values if the specified header exists, otherwise null.
getRequestHeader
(String
the header name, case insensitive.
name
)

Get the values of a HTTP request header if the header exists on the current request.

public MultivaluedMap<String, String>

Returns:

a read-only map of header names and values.
getRequestHeaders
()

Get the values of HTTP request headers.

Field Detail

ACCEPTback to summary
public static final String ACCEPT

See HTTP/1.1 documentation.

ACCEPT_CHARSETback to summary
public static final String ACCEPT_CHARSET

See HTTP/1.1 documentation.

ACCEPT_ENCODINGback to summary
public static final String ACCEPT_ENCODING

See HTTP/1.1 documentation.

ACCEPT_LANGUAGEback to summary
public static final String ACCEPT_LANGUAGE

See HTTP/1.1 documentation.

ALLOWback to summary
public static final String ALLOW

See HTTP/1.1 documentation.

AUTHORIZATIONback to summary
public static final String AUTHORIZATION

See HTTP/1.1 documentation.

CACHE_CONTROLback to summary
public static final String CACHE_CONTROL

See HTTP/1.1 documentation.

CONTENT_DISPOSITIONback to summary
public static final String CONTENT_DISPOSITION

See IETF RFC-2183.

CONTENT_ENCODINGback to summary
public static final String CONTENT_ENCODING

See HTTP/1.1 documentation.

CONTENT_IDback to summary
public static final String CONTENT_ID

See IETF RFC-2392.

CONTENT_LANGUAGEback to summary
public static final String CONTENT_LANGUAGE

See HTTP/1.1 documentation.

CONTENT_LENGTHback to summary
public static final String CONTENT_LENGTH

See HTTP/1.1 documentation.

CONTENT_LOCATIONback to summary
public static final String CONTENT_LOCATION

See HTTP/1.1 documentation.

CONTENT_TYPEback to summary
public static final String CONTENT_TYPE

See HTTP/1.1 documentation.

DATEback to summary
public static final String DATE

See HTTP/1.1 documentation.

ETAGback to summary
public static final String ETAG

See HTTP/1.1 documentation.

EXPECTback to summary
public static final String EXPECT

See HTTP/1.1 documentation.

EXPIRESback to summary
public static final String EXPIRES

See HTTP/1.1 documentation.

HOSTback to summary
public static final String HOST

See HTTP/1.1 documentation.

IF_MATCHback to summary
public static final String IF_MATCH

See HTTP/1.1 documentation.

IF_MODIFIED_SINCEback to summary
public static final String IF_MODIFIED_SINCE

See HTTP/1.1 documentation.

IF_NONE_MATCHback to summary
public static final String IF_NONE_MATCH

See HTTP/1.1 documentation.

IF_UNMODIFIED_SINCEback to summary
public static final String IF_UNMODIFIED_SINCE

See HTTP/1.1 documentation.

LAST_EVENT_ID_HEADERback to summary
public static final String LAST_EVENT_ID_HEADER

"Last-Event-ID" HTTP request header name as defined by SSE specification.

Since
2.1
LAST_MODIFIEDback to summary
public static final String LAST_MODIFIED

See HTTP/1.1 documentation.

LOCATIONback to summary
public static final String LOCATION

See HTTP/1.1 documentation.

RETRY_AFTERback to summary
public static final String RETRY_AFTER

See HTTP/1.1 documentation.

USER_AGENTback to summary
public static final String USER_AGENT

See HTTP/1.1 documentation.

VARYback to summary
public static final String VARY

See HTTP/1.1 documentation.

WWW_AUTHENTICATEback to summary
public static final String WWW_AUTHENTICATE

See HTTP/1.1 documentation.

Method Detail

containsHeaderStringback to summary
public boolean containsHeaderString(String name, String valueSeparatorRegex, Predicate<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 a jakarta.ws.rs.ext.RuntimeDelegate.HeaderDelegate if one is available via jakarta.ws.rs.ext.RuntimeDelegate#createHeaderDelegate(java.lang.Class) for the header value class or using its toString method if a header delegate is not available.

For example: containsHeaderString("cache-control", ",", "no-store"::equalsIgnoreCase) will return true if a Cache-Control header exists that has the value no-store, the value No-Store or the value Max-Age, NO-STORE, no-transform, but false when it has the value no-store;no-transform (missing comma), or the value no - store (whitespace within value).

Parameters
name:String

the message header.

valueSeparatorRegex:String

Regular expression that separates the header value into single values. null does not split.

valuePredicate:Predicate<String>

value must fulfil this predicate.

Returns:boolean

true if 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)
containsHeaderStringback to summary
public default boolean containsHeaderString(String name, Predicate<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 a jakarta.ws.rs.ext.RuntimeDelegate.HeaderDelegate if one is available via jakarta.ws.rs.ext.RuntimeDelegate#createHeaderDelegate(java.lang.Class) for the header value class or using its toString method if a header delegate is not available.

For example: containsHeaderString("cache-control", "no-store"::equalsIgnoreCase) will return true if a Cache-Control header exists that has the value no-store, the value No-Store or the value Max-Age, NO-STORE, no-transform, but false when it has the value no-store;no-transform (missing comma), or the value no - store (whitespace within value).

Parameters
name:String

the message header.

valuePredicate:Predicate<String>

value must fulfil this predicate.

Returns:boolean

true if 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)
getAcceptableLanguagesback to summary
public List<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 wildcard java.util.Locale instance (with language field set to "*") is returned.
Returns:List<Locale>

a read-only list of acceptable languages sorted according to their q-value, with highest preference first.

Exceptions
IllegalStateException:
if called outside the scope of a request.
getAcceptableMediaTypesback to summary
public 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 single wildcard media type instance is returned.
Returns:List<MediaType>

a read-only list of requested response media types sorted according to their q-value, with highest preference first.

Exceptions
IllegalStateException:
if called outside the scope of a request.
getCookiesback to summary
public Map<String, Cookie> getCookies()

Get any cookies that accompanied the request.

Returns:Map<String, Cookie>

a read-only map of cookie name (String) to Cookie.

Exceptions
IllegalStateException:
if called outside the scope of a request
getDateback to summary
public Date getDate()

Get message date.

Returns:Date

the message date, otherwise null if not present.

Since
2.0
getHeaderStringback to summary
public String getHeaderString(String name)

Get a HTTP header as a single string value.

Each single non-string header value is converted to String using a jakarta.ws.rs.ext.RuntimeDelegate.HeaderDelegate if one is available via jakarta.ws.rs.ext.RuntimeDelegate#createHeaderDelegate(java.lang.Class) for the header value class or using its toString method if a header delegate is not available.
Parameters
name:String

the HTTP header.

Returns:String

the HTTP header value. If the HTTP header is not present then null is 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)
getLanguageback to summary
public Locale getLanguage()

Get the language of the request entity.

Returns:Locale

the language of the entity or null if not specified.

Exceptions
IllegalStateException:
if called outside the scope of a request.
getLengthback to summary
public int getLength()

Get Content-Length value.

Returns:int

Content-Length as integer if present and valid number. In other cases returns -1.

Since
2.0
getMediaTypeback to summary
public MediaType getMediaType()

Get the media type of the request entity.

Returns:MediaType

the media type or null if there is no request entity.

Exceptions
IllegalStateException:
if called outside the scope of a request.
getRequestHeaderback to summary
public List<String> getRequestHeader(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 or null if it does not. This is a shortcut for getRequestHeaders().get(name).

Parameters
name:String

the header name, case insensitive.

Returns:List<String>

a read-only list of header values if the specified header exists, otherwise null.

Exceptions
IllegalStateException:
if called outside the scope of a request.
getRequestHeadersback to summary
public MultivaluedMap<String, String> getRequestHeaders()

Get the values of HTTP request headers. The returned Map is case-insensitive wrt. keys and is read-only. The method never returns null.

Returns:MultivaluedMap<String, String>

a read-only map of header names and values.

Exceptions
IllegalStateException:
if called outside the scope of a request.