Interface Headers
-
- All Superinterfaces:
java.lang.Iterable<java.util.Map.Entry<java.lang.String,java.lang.String>>
public interface Headers extends java.lang.Iterable<java.util.Map.Entry<java.lang.String,java.lang.String>>HTTP headers
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description java.util.List<ParameterizedHeaderWithValue>accept()Gets theAccept-Charsetheader value.java.util.List<ParameterizedHeaderWithValue>acceptCharset()Gets theAcceptheader value.java.util.List<ParameterizedHeaderWithValue>acceptEncoding()Gets theAccept-Encodingheader value.java.util.List<ParameterizedHeaderWithValue>acceptLanguage()Gets theAccept-Languageheader value.Headersadd(Headers headers)Adds all headers from another headers object to thisHeadersadd(java.lang.CharSequence name, java.lang.Iterable<?> values)Adds an item to these headers.Headersadd(java.lang.CharSequence name, java.lang.Object value)Adds an item to these headers.Headersadd(java.lang.String name, java.lang.Iterable<?> values)Adds an item to these headers.Headersadd(java.lang.String name, java.lang.Object value)Adds an item to these headers.HeadersaddInt(java.lang.CharSequence name, int value)Adds an integer valueParameterizedHeadercacheControl()Gets theCache-Controlheader value.Headersclear()booleancontains(java.lang.CharSequence name)Returns true if the given parameter is specified with any valuebooleancontains(java.lang.CharSequence name, java.lang.CharSequence value, boolean ignoreCase)Checks if a header with the given name exists with the given value.booleancontains(java.lang.String name)Returns true if the given parameter is specified with any valuebooleancontains(java.lang.String name, java.lang.String value, boolean ignoreCase)Checks if a header with the given name exists with the given value.booleancontainsValue(java.lang.CharSequence name, java.lang.CharSequence value, boolean ignoreCase)Similar tocontains(String, String, boolean)but returns true even if a value occurs in a comma-separated header list.jakarta.ws.rs.core.MediaTypecontentType()Gets the parsedContent-Typeheader value.java.util.List<java.util.Map.Entry<java.lang.String,java.lang.String>>entries()java.util.List<ForwardedHeader>forwarded()Gets theForwardedheader value.java.lang.Stringget(java.lang.CharSequence name)Gets the value with the given name, or null if there is no parameter with that name.java.lang.Stringget(java.lang.CharSequence name, java.lang.String defaultValue)Gets the value with the given name, or the default value if there is no parameter with that name.java.lang.Stringget(java.lang.String name)Gets the value with the given name, or null if there is no parameter with that name.java.util.List<java.lang.String>getAll(java.lang.CharSequence name)Gets all the parameters with the given name, or an empty list if none are found.java.util.List<java.lang.String>getAll(java.lang.String name)Gets all the parameters with the given name, or an empty list if none are found.booleangetBoolean(java.lang.String name)Gets a parameter as a boolean, where values such astrue,onandyesas considered true, and other values (or no parameter with the name) is considered false.doublegetDouble(java.lang.String name, double defaultValue)Gets the parameter as a double, or returns the default value if it was not specified or was in an invalid format.floatgetFloat(java.lang.String name, float defaultValue)Gets the parameter as a float, or returns the default value if it was not specified or was in an invalid format.intgetInt(java.lang.CharSequence name, int defaultValue)Gets the parameter as an integer, or returns the default value if it was not specified or was in an invalid format.longgetLong(java.lang.String name, long defaultValue)Gets the parameter as a long, or returns the default value if it was not specified or was in an invalid format.java.lang.LonggetTimeMillis(java.lang.CharSequence name)Gets a date header.longgetTimeMillis(java.lang.CharSequence name, long defaultValue)Gets a date header.booleanhasBody()Returns true if the headers suggest there is a message body by checking if there is aHeaderNames.TRANSFER_ENCODINGheader or theHeaderNames.CONTENT_LENGTHis greater than 0.static Headershttp1Headers()Creates new headers for HTTP1 requestsstatic Headershttp2Headers()Creates new headers for HTTP2 requestsbooleanisEmpty()java.util.Iterator<java.util.Map.Entry<java.lang.String,java.lang.String>>iterator()java.util.Set<java.lang.String>names()Headersremove(java.lang.CharSequence name)Removes a header.Headersremove(java.lang.String name)Removes a header.Headersset(Headers headers)Removes all the current headers and adds them from the given headers.Headersset(java.lang.CharSequence name, java.lang.Iterable<?> values)Sets a header value list.Headersset(java.lang.CharSequence name, java.lang.Object value)Sets a header value.Headersset(java.lang.String name, java.lang.Iterable<?> values)Sets a header value list.Headersset(java.lang.String name, java.lang.Object value)Sets a header value.HeaderssetAll(Headers headers)Sets all the values from the given headers object, overwriting any existing headers with the same names.HeaderssetInt(java.lang.CharSequence name, int value)Sets the given integer value, replacing the existing value if it is already set.intsize()java.lang.StringtoString()Returns a string representation of the headers.java.lang.StringtoString(java.util.Collection<java.lang.String> toSuppress)Returns a string representation of the headers with selected header values replaced with the string(hidden).
-
-
-
Method Detail
-
get
java.lang.String get(java.lang.String name)
Gets the value with the given name, or null if there is no parameter with that name.
If there are multiple parameters with the same name, the first one is returned.
- Parameters:
name- The name of the parameter to get- Returns:
- The value, or null
-
get
java.lang.String get(java.lang.CharSequence name)
Gets the value with the given name, or null if there is no parameter with that name.
If there are multiple parameters with the same name, the first one is returned.
- Parameters:
name- The name of the parameter to get- Returns:
- The value, or null
-
get
java.lang.String get(java.lang.CharSequence name, java.lang.String defaultValue)Gets the value with the given name, or the default value if there is no parameter with that name.
If there are multiple parameters with the same name, the first one is returned.
- Parameters:
name- The name of the parameter to getdefaultValue- The default value to use if there is no given value- Returns:
- The value of the parameter, or the default value
-
getInt
int getInt(java.lang.CharSequence name, int defaultValue)Gets the parameter as an integer, or returns the default value if it was not specified or was in an invalid format.- Parameters:
name- The name of the parameter.defaultValue- The value to use if none was specified, or an invalid format was used.- Returns:
- Returns the parameter value as an integer.
-
getLong
long getLong(java.lang.String name, long defaultValue)Gets the parameter as a long, or returns the default value if it was not specified or was in an invalid format.- Parameters:
name- The name of the parameter.defaultValue- The value to use if none was specified, or an invalid format was used.- Returns:
- Returns the parameter value as a long.
-
getFloat
float getFloat(java.lang.String name, float defaultValue)Gets the parameter as a float, or returns the default value if it was not specified or was in an invalid format.- Parameters:
name- The name of the parameter.defaultValue- The value to use if none was specified, or an invalid format was used.- Returns:
- Returns the parameter value as a float.
-
getDouble
double getDouble(java.lang.String name, double defaultValue)Gets the parameter as a double, or returns the default value if it was not specified or was in an invalid format.- Parameters:
name- The name of the parameter.defaultValue- The value to use if none was specified, or an invalid format was used.- Returns:
- Returns the parameter value as a double.
-
getBoolean
boolean getBoolean(java.lang.String name)
Gets a parameter as a boolean, where values such as
true,onandyesas considered true, and other values (or no parameter with the name) is considered false.This can be used to access checkbox values as booleans.
- Parameters:
name- The name of the parameter.- Returns:
- Returns true if the value was truthy, or false if it was falsy or not specified.
-
getTimeMillis
java.lang.Long getTimeMillis(java.lang.CharSequence name)
Gets a date header.This converts the string date values into milliseconds
- Parameters:
name- The header name- Returns:
- The value in milliseconds of the date header, or null if not found
-
getTimeMillis
long getTimeMillis(java.lang.CharSequence name, long defaultValue)Gets a date header.This converts the string date values into milliseconds
- Parameters:
name- The header namedefaultValue- The default to use if no date header is available- Returns:
- The value in milliseconds of the date header, or the default if not found
-
getAll
java.util.List<java.lang.String> getAll(java.lang.String name)
Gets all the parameters with the given name, or an empty list if none are found.- Parameters:
name- The parameter name to get- Returns:
- All values of the parameter with the given name
-
getAll
java.util.List<java.lang.String> getAll(java.lang.CharSequence name)
Gets all the parameters with the given name, or an empty list if none are found.- Parameters:
name- The parameter name to get- Returns:
- All values of the parameter with the given name
-
entries
java.util.List<java.util.Map.Entry<java.lang.String,java.lang.String>> entries()
- Returns:
- All the headers
-
contains
boolean contains(java.lang.String name)
Returns true if the given parameter is specified with any value- Parameters:
name- The name of the value- Returns:
- True if it's specified; otherwise false.
-
contains
boolean contains(java.lang.CharSequence name)
Returns true if the given parameter is specified with any value- Parameters:
name- The name of the value- Returns:
- True if it's specified; otherwise false.
-
iterator
java.util.Iterator<java.util.Map.Entry<java.lang.String,java.lang.String>> iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<java.util.Map.Entry<java.lang.String,java.lang.String>>- Returns:
- An iterator to iterate through the headers
-
isEmpty
boolean isEmpty()
- Returns:
- True if there are no headers
-
size
int size()
- Returns:
- The number of headers. Repeated headers are counted twice.
-
names
java.util.Set<java.lang.String> names()
- Returns:
- The header names in these headers
-
add
Headers add(java.lang.String name, java.lang.Object value)
Adds an item to these headers. If a header with the given name already exists then this value is added rather than replaced.- Parameters:
name- The header namevalue- The value- Returns:
- This headers object
-
add
Headers add(java.lang.CharSequence name, java.lang.Object value)
Adds an item to these headers. If a header with the given name already exists then this value is added rather than replaced.- Parameters:
name- The header namevalue- The value- Returns:
- This headers object
-
add
Headers add(java.lang.String name, java.lang.Iterable<?> values)
Adds an item to these headers. If a header with the given name already exists then this value is added rather than replaced.- Parameters:
name- The header namevalues- The values- Returns:
- This headers object
-
add
Headers add(java.lang.CharSequence name, java.lang.Iterable<?> values)
Adds an item to these headers. If a header with the given name already exists then this value is added rather than replaced.- Parameters:
name- The header namevalues- The value- Returns:
- This headers object
-
add
Headers add(Headers headers)
Adds all headers from another headers object to this- Parameters:
headers- The headers to add- Returns:
- This headers object
-
addInt
Headers addInt(java.lang.CharSequence name, int value)
Adds an integer value- Parameters:
name- The header namevalue- The value- Returns:
- This headers object
-
set
Headers set(java.lang.String name, java.lang.Object value)
Sets a header value. If a header with the given name already exists then this replaces it.- Parameters:
name- The header namevalue- The value- Returns:
- This headers object
-
set
Headers set(java.lang.CharSequence name, java.lang.Object value)
Sets a header value. If a header with the given name already exists then this replaces it.- Parameters:
name- The header namevalue- The value- Returns:
- This headers object
-
set
Headers set(java.lang.String name, java.lang.Iterable<?> values)
Sets a header value list. If a header with the given name already exists then this replaces it.- Parameters:
name- The header namevalues- The value- Returns:
- This headers object
-
set
Headers set(java.lang.CharSequence name, java.lang.Iterable<?> values)
Sets a header value list. If a header with the given name already exists then this replaces it.- Parameters:
name- The header namevalues- The value- Returns:
- This headers object
-
set
Headers set(Headers headers)
Removes all the current headers and adds them from the given headers.- Parameters:
headers- The headers to use- Returns:
- This headers object
-
setAll
Headers setAll(Headers headers)
Sets all the values from the given headers object, overwriting any existing headers with the same names.- Parameters:
headers- The headers to use- Returns:
- This headers object
-
setInt
Headers setInt(java.lang.CharSequence name, int value)
Sets the given integer value, replacing the existing value if it is already set.- Parameters:
name- The header namevalue- The value to set- Returns:
- This headers object
-
remove
Headers remove(java.lang.String name)
Removes a header. Does nothing if the header is not set.- Parameters:
name- The header to remove- Returns:
- This headers object
-
remove
Headers remove(java.lang.CharSequence name)
Removes a header. Does nothing if the header is not set.- Parameters:
name- The header to remove- Returns:
- This headers object
-
clear
Headers clear()
- Returns:
- Removes all the headers from this object
-
contains
boolean contains(java.lang.String name, java.lang.String value, boolean ignoreCase)Checks if a header with the given name exists with the given value.- Parameters:
name- The case-insensitive header name to check.value- The value to check for.ignoreCase- If true, the case of the value is ignored.- Returns:
- True if a header name with the given value exists.
-
contains
boolean contains(java.lang.CharSequence name, java.lang.CharSequence value, boolean ignoreCase)Checks if a header with the given name exists with the given value.- Parameters:
name- The case-insensitive header name to check.value- The value to check for.ignoreCase- If true, the case of the value is ignored.- Returns:
- True if a header name with the given value exists.
-
containsValue
boolean containsValue(java.lang.CharSequence name, java.lang.CharSequence value, boolean ignoreCase)Similar tocontains(String, String, boolean)but returns true even if a value occurs in a comma-separated header list.- Parameters:
name- The case-insensitive header name to check.value- The value to check for.ignoreCase- If true, the case of the value is ignored.- Returns:
- True if a header name with the given value exists.
-
hasBody
boolean hasBody()
Returns true if the headers suggest there is a message body by checking if there is aHeaderNames.TRANSFER_ENCODINGheader or theHeaderNames.CONTENT_LENGTHis greater than 0.- Returns:
- True if there should be a body; otherwise false;
-
accept
java.util.List<ParameterizedHeaderWithValue> accept()
Gets the
Accept-Charsetheader value.For example, if a client sends
text/html,application/xml;q=0.9then this would return a list of two values: text/html, and application/xml where application/xml has a parameterqof value0.9- Returns:
- Returns a parsed
Acceptheader, or an empty list if none specified.
-
acceptCharset
java.util.List<ParameterizedHeaderWithValue> acceptCharset()
Gets the
Acceptheader value.For example, if a client sends
iso-8859-5, unicode-1-1;q=0.8then this would return a list of two values: iso-8859-5, and unicode-1-1 where unicode-1-1 has a parameterqof value0.8- Returns:
- Returns a parsed
Accept-Charsetheader, or an empty list if none specified.
-
acceptEncoding
java.util.List<ParameterizedHeaderWithValue> acceptEncoding()
Gets the
Accept-Encodingheader value.For example, if a client sends
gzip, deflatethen this would return a list of two values: gzip and deflate- Returns:
- Returns a parsed
Accept-Encodingheader, or an empty list if none specified.
-
forwarded
java.util.List<ForwardedHeader> forwarded()
Gets the
Forwardedheader value.For example, if a client sends
for=192.0.2.60;proto=http;by=203.0.113.43then this would return a list of length one that has for, proto, and by values.If there is no Forwarded header, however there are X-Forwarded-* headers, then those will be used to generate pseudo-forwarded headers.
- Returns:
- Returns a parsed
Forwardedheader, or an empty list if none specified.
-
acceptLanguage
java.util.List<ParameterizedHeaderWithValue> acceptLanguage()
Gets the
Accept-Languageheader value.For example, if a client sends
en-US,en;q=0.5then this would return a list of two values: en-US and en where en has aqvalue of0.5- Returns:
- Returns a parsed
Accept-Languageheader, or an empty list if none specified.
-
cacheControl
ParameterizedHeader cacheControl()
Gets theCache-Controlheader value.- Returns:
- A map of cache control directives to their optional values. If no cache-control is in the header, then the resulting map will be empty.
-
contentType
jakarta.ws.rs.core.MediaType contentType()
Gets the parsedContent-Typeheader value.- Returns:
- The media type of the content specified by the headers, or
nullif not set.
-
toString
java.lang.String toString()
Returns a string representation of the headers. Note: The following headers will have their actual values replaced with the string(hidden)in order to protect potentially sensitive information:authorization,cookieandset-cookie.If you wish to print all values or customize the header values that are hidden, use
toString(Collection)- Overrides:
toStringin classjava.lang.Object- Returns:
- a string representation of these headers
-
toString
java.lang.String toString(java.util.Collection<java.lang.String> toSuppress)
Returns a string representation of the headers with selected header values replaced with the string(hidden).This may be useful where headers are logged for diagnostic purposes while not revealing values that are held in potentially sensitive headers.
- Parameters:
toSuppress- A collection of case-insensitive header names which will not have their values printed. Pass an empty collection to print all header values. Anullvalue will hide the header values as defined ontoString().- Returns:
- a string representation of these headers
-
http1Headers
static Headers http1Headers()
Creates new headers for HTTP1 requests- Returns:
- An empty headers object.
-
http2Headers
static Headers http2Headers()
Creates new headers for HTTP2 requests- Returns:
- An empty headers object.
-
-