public interface HttpHeaders
extends java.lang.Iterable<java.util.Map.Entry<java.lang.CharSequence,java.lang.CharSequence>>
All header field names are compared in a case-insensitive manner.
Modifier and Type | Method and Description |
---|---|
HttpHeaders |
add(java.lang.CharSequence name,
java.lang.CharSequence... values)
Adds new headers with the specified
name and values . |
HttpHeaders |
add(java.lang.CharSequence name,
java.lang.CharSequence value)
Adds a new header with the specified
name and value . |
HttpHeaders |
add(java.lang.CharSequence name,
java.lang.Iterable<? extends java.lang.CharSequence> values)
Adds new headers with the specified
name and values . |
default HttpHeaders |
add(java.lang.CharSequence name,
java.util.Iterator<? extends java.lang.CharSequence> valuesItr)
Adds new headers with the specified
name and values . |
HttpHeaders |
add(HttpHeaders headers)
Adds all header names and values of
headers to this object. |
default HttpHeaders |
addCookie(java.lang.CharSequence name,
java.lang.CharSequence value)
|
HttpHeaders |
addCookie(HttpCookiePair cookie)
Adds a cookie.
|
default HttpHeaders |
addSetCookie(java.lang.CharSequence name,
java.lang.CharSequence value)
|
HttpHeaders |
addSetCookie(HttpSetCookie cookie)
Adds a set-cookie.
|
HttpHeaders |
clear()
Removes all headers.
|
default boolean |
contains(java.lang.CharSequence name)
Returns
true if a header with the name exists, false otherwise. |
boolean |
contains(java.lang.CharSequence name,
java.lang.CharSequence value)
Returns
true if a header with the name and value exists, false otherwise. |
boolean |
containsIgnoreCase(java.lang.CharSequence name,
java.lang.CharSequence value)
Returns
true if a header with the name and value exists, false otherwise. |
java.lang.CharSequence |
get(java.lang.CharSequence name)
Returns the value of a header with the specified name.
|
default java.lang.CharSequence |
get(java.lang.CharSequence name,
java.lang.CharSequence defaultValue)
Returns the value of a header with the specified name.
|
java.lang.CharSequence |
getAndRemove(java.lang.CharSequence name)
Returns the value of a header with the specified name and removes it from this object.
|
default java.lang.CharSequence |
getAndRemove(java.lang.CharSequence name,
java.lang.CharSequence defaultValue)
Returns the value of a header with the specified name and removes it from this object.
|
HttpCookiePair |
getCookie(java.lang.CharSequence name)
Gets a cookie identified by
name . |
default java.lang.Iterable<? extends HttpCookiePair> |
getCookies()
Gets all the cookies.
|
default java.lang.Iterable<? extends HttpCookiePair> |
getCookies(java.lang.CharSequence name)
Gets the cookies with the same name.
|
java.util.Iterator<? extends HttpCookiePair> |
getCookiesIterator()
Gets all the cookies.
|
java.util.Iterator<? extends HttpCookiePair> |
getCookiesIterator(java.lang.CharSequence name)
Gets the cookies with the same name.
|
HttpSetCookie |
getSetCookie(java.lang.CharSequence name)
Gets a set-cookie identified by
name . |
default java.lang.Iterable<? extends HttpSetCookie> |
getSetCookies()
Gets all the set-cookies.
|
default java.lang.Iterable<? extends HttpSetCookie> |
getSetCookies(java.lang.CharSequence name)
Gets the set-cookies with the same name.
|
default java.lang.Iterable<? extends HttpSetCookie> |
getSetCookies(java.lang.CharSequence name,
java.lang.CharSequence domain,
java.lang.CharSequence path)
Gets the set-cookies with the same name.
|
java.util.Iterator<? extends HttpSetCookie> |
getSetCookiesIterator()
Gets all the set-cookies.
|
java.util.Iterator<? extends HttpSetCookie> |
getSetCookiesIterator(java.lang.CharSequence name)
Gets the set-cookies with the same name.
|
java.util.Iterator<? extends HttpSetCookie> |
getSetCookiesIterator(java.lang.CharSequence name,
java.lang.CharSequence domain,
java.lang.CharSequence path)
Gets the set-cookies with the same name.
|
boolean |
isEmpty()
|
java.util.Iterator<java.util.Map.Entry<java.lang.CharSequence,java.lang.CharSequence>> |
iterator() |
java.util.Set<? extends java.lang.CharSequence> |
names()
Returns a
Set of all header names in this object. |
boolean |
remove(java.lang.CharSequence name)
Removes all headers with the specified
name . |
boolean |
remove(java.lang.CharSequence name,
java.lang.CharSequence value)
Removes specific value(s) from the specified header
name . |
boolean |
removeCookies(java.lang.CharSequence name)
Removes all cookie identified by
name . |
boolean |
removeIgnoreCase(java.lang.CharSequence name,
java.lang.CharSequence value)
Removes specific value(s) from the specified header
name . |
boolean |
removeSetCookies(java.lang.CharSequence name)
Removes all set-cookie identified by
name . |
boolean |
removeSetCookies(java.lang.CharSequence name,
java.lang.CharSequence domain,
java.lang.CharSequence path)
Removes all set-cookie identified by
name . |
default HttpHeaders |
replace(HttpHeaders headers)
Removes all header names contained in
headers from this object, and then adds all headers contained in
headers . |
HttpHeaders |
set(java.lang.CharSequence name,
java.lang.CharSequence... values)
Sets a header with the specified
name and values . |
HttpHeaders |
set(java.lang.CharSequence name,
java.lang.CharSequence value)
Sets a header with the specified
name and value . |
HttpHeaders |
set(java.lang.CharSequence name,
java.lang.Iterable<? extends java.lang.CharSequence> values)
Sets a new header with the specified
name and values . |
default HttpHeaders |
set(java.lang.CharSequence name,
java.util.Iterator<? extends java.lang.CharSequence> valueItr)
Sets a new header with the specified
name and values . |
default HttpHeaders |
set(HttpHeaders headers)
Clears the current header entries and copies all header entries of the specified
headers object. |
int |
size()
Returns the number of headers in this object.
|
default java.util.Spliterator<java.util.Map.Entry<java.lang.CharSequence,java.lang.CharSequence>> |
spliterator() |
java.lang.String |
toString()
Returns a
String representation of this HttpHeaders . |
default java.lang.String |
toString(java.util.function.BiFunction<? super java.lang.CharSequence,? super java.lang.CharSequence,java.lang.CharSequence> filter)
Builds a string which represents all the content in this
HttpHeaders in which sensitive headers can be
filtered via filter . |
default java.lang.Iterable<? extends java.lang.CharSequence> |
values(java.lang.CharSequence name)
Returns all values for the header with the specified name.
|
java.util.Iterator<? extends java.lang.CharSequence> |
valuesIterator(java.lang.CharSequence name)
Returns all values for the header with the specified name.
|
@Nullable java.lang.CharSequence get(java.lang.CharSequence name)
name
- the name of the header to retrieve.null
if there's no such header.default java.lang.CharSequence get(java.lang.CharSequence name, java.lang.CharSequence defaultValue)
name
- the name of the header to retrieve.defaultValue
- the default value.defaultValue
if there is no such header.@Nullable java.lang.CharSequence getAndRemove(java.lang.CharSequence name)
name
- the name of the header to retrieve.null
if there is no such header.default java.lang.CharSequence getAndRemove(java.lang.CharSequence name, java.lang.CharSequence defaultValue)
name
- the name of the header to retrieve.defaultValue
- the default value.defaultValue
if there is no such header.default java.lang.Iterable<? extends java.lang.CharSequence> values(java.lang.CharSequence name)
name
- the name of the header to retrieve.Iterable
of header values or an empty Iterable
if no values are found.if minimal object allocation is required.
java.util.Iterator<? extends java.lang.CharSequence> valuesIterator(java.lang.CharSequence name)
name
- the name of the header to retrieve.Iterator
of header values or an empty Iterator
if no values are found.if Iterable is preferred, at the expense of more object allocation.
default boolean contains(java.lang.CharSequence name)
true
if a header with the name
exists, false
otherwise.name
- the header name.true
if name
exists.boolean contains(java.lang.CharSequence name, java.lang.CharSequence value)
true
if a header with the name
and value
exists, false
otherwise.name
- the header name.value
- the header value of the header to find.true
if a name
, value
pair exists.boolean containsIgnoreCase(java.lang.CharSequence name, java.lang.CharSequence value)
true
if a header with the name
and value
exists, false
otherwise.
Case insensitive compare is done on the value.
name
- the name of the header to find.value
- the value of the header to find.true
if found.int size()
boolean isEmpty()
true
if size()
equals 0
.java.util.Set<? extends java.lang.CharSequence> names()
Set
of all header names in this object. The returned Set
cannot be modified.Set
of all header names in this object. The returned Set
cannot be modified.HttpHeaders add(java.lang.CharSequence name, java.lang.CharSequence value)
name
and value
.name
- the name of the header.value
- the value of the header.this
.HttpHeaders add(java.lang.CharSequence name, java.lang.Iterable<? extends java.lang.CharSequence> values)
name
and values
. This method is semantically equivalent to:
for (T value : values) { headers.add(name, value); }
name
- the name of the header.values
- the values of the header.this
.default HttpHeaders add(java.lang.CharSequence name, java.util.Iterator<? extends java.lang.CharSequence> valuesItr)
name
and values
. This method is semantically equivalent to:
while (valueItr.hasNext()) { headers.add(name, valueItr.next()); }
name
- the name of the header.valuesItr
- the values of the header.this
.HttpHeaders add(java.lang.CharSequence name, java.lang.CharSequence... values)
name
and values
. This method is semantically equivalent to:
for (T value : values) { headers.add(name, value); }
name
- the name of the header.values
- the values of the header.this
.HttpHeaders add(HttpHeaders headers)
headers
to this object.headers
- the headers to add.this
.HttpHeaders set(java.lang.CharSequence name, java.lang.CharSequence value)
name
and value
. Any existing headers with the same name are
overwritten.name
- the name of the header.value
- the value of the header.this
.HttpHeaders set(java.lang.CharSequence name, java.lang.Iterable<? extends java.lang.CharSequence> values)
name
and values
. This method is equivalent to:
headers.remove(name); for (T value : values) { headers.add(name, value); }
name
- the name of the header.values
- the values of the header.this
.default HttpHeaders set(java.lang.CharSequence name, java.util.Iterator<? extends java.lang.CharSequence> valueItr)
name
and values
. This method is equivalent to:
headers.remove(name); while (valueItr.hasNext()) { headers.add(name, valueItr.next()); }
name
- the name of the header.valueItr
- the values of the header.this
.HttpHeaders set(java.lang.CharSequence name, java.lang.CharSequence... values)
name
and values
. Any existing headers with this name are
removed. This method is equivalent to:
headers.remove(name); for (T value : values) { headers.add(name, value); }
name
- the name of the header.values
- the values of the header.this
.default HttpHeaders set(HttpHeaders headers)
headers
object.headers
- the headers object which contains new values.this
.default HttpHeaders replace(HttpHeaders headers)
headers
from this object, and then adds all headers contained in
headers
.headers
- the headers used to remove names and then add new entries.this
.boolean remove(java.lang.CharSequence name)
name
.name
- the name of the header.true
if at least one entry has been removed.boolean remove(java.lang.CharSequence name, java.lang.CharSequence value)
name
. If the header has more than one identical
values, all of them will be removed.name
- the name of the header.value
- the value of the header to remove.true
if at least one value has been removed.boolean removeIgnoreCase(java.lang.CharSequence name, java.lang.CharSequence value)
name
. If the header has more than one identical
values, all of them will be removed.
Case insensitive compare is done on the value.
name
- the name of the header.value
- the value of the header to remove.true
if at least one value has been removed.HttpHeaders clear()
this
.java.util.Iterator<java.util.Map.Entry<java.lang.CharSequence,java.lang.CharSequence>> iterator()
iterator
in interface java.lang.Iterable<java.util.Map.Entry<java.lang.CharSequence,java.lang.CharSequence>>
default java.util.Spliterator<java.util.Map.Entry<java.lang.CharSequence,java.lang.CharSequence>> spliterator()
spliterator
in interface java.lang.Iterable<java.util.Map.Entry<java.lang.CharSequence,java.lang.CharSequence>>
java.lang.String toString()
String
representation of this HttpHeaders
. To avoid accidentally logging sensitive
information, implementations should be cautious about logging header content and consider using
toString(BiFunction)
.toString
in class java.lang.Object
String
representation of this HttpHeaders
.default java.lang.String toString(java.util.function.BiFunction<? super java.lang.CharSequence,? super java.lang.CharSequence,java.lang.CharSequence> filter)
HttpHeaders
in which sensitive headers can be
filtered via filter
.filter
- a function that accepts the header name and value and returns the filtered value.HttpHeaders
.@Nullable HttpCookiePair getCookie(java.lang.CharSequence name)
name
. If there
is more than one HttpSetCookie
for the specified name, the first HttpSetCookie
in insertion order
is returned.name
- the cookie-name to look for.HttpSetCookie
identified by name
.@Nullable HttpSetCookie getSetCookie(java.lang.CharSequence name)
name
. If
there is more than one HttpSetCookie
for the specified name, the first HttpSetCookie
in insertion
order is returned.name
- the cookie-name to look for.HttpSetCookie
identified by name
.default java.lang.Iterable<? extends HttpCookiePair> getCookies()
Iterable
with all the cookies.if minimal object allocation is required.
java.util.Iterator<? extends HttpCookiePair> getCookiesIterator()
Iterator
with all the cookies.if Iterable is preferred, at the expense of more object allocation.
default java.lang.Iterable<? extends HttpCookiePair> getCookies(java.lang.CharSequence name)
name
- the cookie-name of the HttpSetCookie
s to get.Iterable
where all the HttpSetCookie
s have the same name.if minimal object allocation is required.
java.util.Iterator<? extends HttpCookiePair> getCookiesIterator(java.lang.CharSequence name)
name
- the cookie-name of the HttpSetCookie
s to get.Iterator
where all the HttpSetCookie
s have the same name.if Iterable is preferred, at the expense of more object allocation.
default java.lang.Iterable<? extends HttpSetCookie> getSetCookies()
Iterable
with all the
set-cookies.if minimal object allocation is required.
java.util.Iterator<? extends HttpSetCookie> getSetCookiesIterator()
Iterator
with all the
set-cookies.if Iterable is preferred, at the expense of more object allocation.
default java.lang.Iterable<? extends HttpSetCookie> getSetCookies(java.lang.CharSequence name)
name
- the cookie-name of the HttpSetCookie
s to get.Iterable
where all the HttpSetCookie
s have the same name.if minimal object allocation is required.
java.util.Iterator<? extends HttpSetCookie> getSetCookiesIterator(java.lang.CharSequence name)
name
- the cookie-name of the HttpSetCookie
s to get.Iterator
where all the HttpSetCookie
s have the same name.if Iterable is preferred, at the expense of more object allocation.
default java.lang.Iterable<? extends HttpSetCookie> getSetCookies(java.lang.CharSequence name, java.lang.CharSequence domain, java.lang.CharSequence path)
name
- the cookie-name of the HttpSetCookie
s to get.domain
- the domain-value of the HttpSetCookie
s to get. This value may be matched according
to the Domain Matching algorithm.path
- the path-av of the HttpSetCookie
s to get. This value may be matched according
to the Path Matching algorithm.Iterable
where all the HttpSetCookie
s match the parameter values.if minimal object allocation is required.
java.util.Iterator<? extends HttpSetCookie> getSetCookiesIterator(java.lang.CharSequence name, java.lang.CharSequence domain, java.lang.CharSequence path)
name
- the cookie-name of the HttpSetCookie
s to get.domain
- the domain-value of the HttpSetCookie
s to get. This value may be matched according
to the Domain Matching algorithm.path
- the path-av of the HttpSetCookie
s to get. This value may be matched according
to the Path Matching algorithm.Iterator
where all the HttpSetCookie
s match the parameter values.if Iterable is preferred, at the expense of more
object allocation.
HttpHeaders addCookie(HttpCookiePair cookie)
This may result in multiple HttpCookiePair
s with same name.
cookie
- the cookie to add.this
.default HttpHeaders addCookie(java.lang.CharSequence name, java.lang.CharSequence value)
name
and
value
.
This may result in multiple HttpSetCookie
s with same name. Added cookie will not be wrapped, not secure,
and not HTTP-only, with no path, domain, expire date and maximum age.
name
- the name of the cookie.value
- the value of the cookie.this
.HttpHeaders addSetCookie(HttpSetCookie cookie)
This may result in multiple HttpSetCookie
s with same name.
cookie
- the cookie to add.this
.default HttpHeaders addSetCookie(java.lang.CharSequence name, java.lang.CharSequence value)
name
and value
.
This may result in multiple HttpSetCookie
s with same name. Added cookie will not be wrapped, not secure,
and not HTTP-only, with no path, domain, expire date and maximum age.
name
- the name of the cookie.value
- the value of the cookie.this
.boolean removeCookies(java.lang.CharSequence name)
name
.name
- the cookie-name of the HttpSetCookie
s to remove.true
if at least one entry has been removed.boolean removeSetCookies(java.lang.CharSequence name)
name
.name
- the cookie-name of the HttpSetCookie
s to remove.true
if at least one entry has been removed.boolean removeSetCookies(java.lang.CharSequence name, java.lang.CharSequence domain, java.lang.CharSequence path)
name
.name
- the cookie-name of the HttpSetCookie
s to remove.domain
- the domain-value of the HttpSetCookie
s to remove. This value may be matched according
to the Domain Matching algorithm.path
- the path-av of the HttpSetCookie
s to remove. This value may be matched according
to the Path Matching algorithm.true
if at least one entry has been removed.