Package io.servicetalk.http.api
Interface HttpHeaders
- All Superinterfaces:
Iterable<Map.Entry<CharSequence,
CharSequence>>
- All Known Implementing Classes:
EmptyHttpHeaders
HTTP Header Fields.
All header field names are compared in a case-insensitive manner.
-
Method Summary
Modifier and TypeMethodDescriptionadd
(HttpHeaders headers) Adds all header names and values ofheaders
to this object.add
(CharSequence name, CharSequence value) Adds a new header with the specifiedname
andvalue
.add
(CharSequence name, CharSequence... values) Adds new headers with the specifiedname
andvalues
.add
(CharSequence name, Iterable<? extends CharSequence> values) Adds new headers with the specifiedname
andvalues
.default HttpHeaders
add
(CharSequence name, Iterator<? extends CharSequence> valuesItr) Adds new headers with the specifiedname
andvalues
.addCookie
(HttpCookiePair cookie) Adds a cookie.default HttpHeaders
addCookie
(CharSequence name, CharSequence value) addSetCookie
(HttpSetCookie cookie) Adds a set-cookie.default HttpHeaders
addSetCookie
(CharSequence name, CharSequence value) clear()
Removes all headers.default boolean
contains
(CharSequence name) Returnstrue
if a header with thename
exists,false
otherwise.boolean
contains
(CharSequence name, CharSequence value) Returnstrue
if a header with thename
andvalue
exists,false
otherwise.boolean
containsIgnoreCase
(CharSequence name, CharSequence value) Returnstrue
if a header with thename
andvalue
exists,false
otherwise.get
(CharSequence name) Returns the value of a header with the specified name.default CharSequence
get
(CharSequence name, CharSequence defaultValue) Returns the value of a header with the specified name.getAndRemove
(CharSequence name) Returns the value of a header with the specified name and removes it from this object.default CharSequence
getAndRemove
(CharSequence name, CharSequence defaultValue) Returns the value of a header with the specified name and removes it from this object.getCookie
(CharSequence name) Gets a cookie identified byname
.default Iterable<? extends HttpCookiePair>
Gets all the cookies.default Iterable<? extends HttpCookiePair>
getCookies
(CharSequence name) Gets the cookies with the same name.Iterator<? extends HttpCookiePair>
Gets all the cookies.Iterator<? extends HttpCookiePair>
Gets the cookies with the same name.getSetCookie
(CharSequence name) Gets a set-cookie identified byname
.default Iterable<? extends HttpSetCookie>
Gets all the set-cookies.default Iterable<? extends HttpSetCookie>
getSetCookies
(CharSequence name) Gets the set-cookies with the same name.default Iterable<? extends HttpSetCookie>
getSetCookies
(CharSequence name, CharSequence domain, CharSequence path) Gets the set-cookies with the same name.Iterator<? extends HttpSetCookie>
Gets all the set-cookies.Iterator<? extends HttpSetCookie>
Gets the set-cookies with the same name.Iterator<? extends HttpSetCookie>
getSetCookiesIterator
(CharSequence name, CharSequence domain, CharSequence path) Gets the set-cookies with the same name.boolean
isEmpty()
iterator()
Set<? extends CharSequence>
names()
Returns aSet
of all header names in this object.boolean
remove
(CharSequence name) Removes all headers with the specifiedname
.boolean
remove
(CharSequence name, CharSequence value) Removes specific value(s) from the specified headername
.boolean
removeCookies
(CharSequence name) Removes all cookie identified byname
.boolean
removeIgnoreCase
(CharSequence name, CharSequence value) Removes specific value(s) from the specified headername
.boolean
removeSetCookies
(CharSequence name) Removes all set-cookie identified byname
.boolean
removeSetCookies
(CharSequence name, CharSequence domain, CharSequence path) Removes all set-cookie identified byname
.default HttpHeaders
replace
(HttpHeaders headers) Removes all header names contained inheaders
from this object, and then adds all headers contained inheaders
.default HttpHeaders
set
(HttpHeaders headers) Clears the current header entries and copies all header entries of the specifiedheaders
object.set
(CharSequence name, CharSequence value) Sets a header with the specifiedname
andvalue
.set
(CharSequence name, CharSequence... values) Sets a header with the specifiedname
andvalues
.set
(CharSequence name, Iterable<? extends CharSequence> values) Sets a new header with the specifiedname
andvalues
.default HttpHeaders
set
(CharSequence name, Iterator<? extends CharSequence> valueItr) Sets a new header with the specifiedname
andvalues
.int
size()
Returns the number of headers in this object.default Spliterator<Map.Entry<CharSequence,
CharSequence>> toString()
Returns aString
representation of thisHttpHeaders
.default String
toString
(BiFunction<? super CharSequence, ? super CharSequence, CharSequence> filter) Builds a string which represents all the content in thisHttpHeaders
in which sensitive headers can be filtered viafilter
.default Iterable<? extends CharSequence>
values
(CharSequence name) Returns all values for the header with the specified name.Iterator<? extends CharSequence>
valuesIterator
(CharSequence name) Returns all values for the header with the specified name.
-
Method Details
-
get
Returns the value of a header with the specified name. If there is more than one value for the specified name, the first value in insertion order is returned.- Parameters:
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.
-
get
Returns the value of a header with the specified name. If there is more than one value for the specified name, the first value in insertion order is returned.- Parameters:
name
- the name of the header to retrieve.defaultValue
- the default value.- Returns:
- the first header value or
defaultValue
if there is no such header.
-
getAndRemove
Returns the value of a header with the specified name and removes it from this object. If there is more than one value for the specified name, the first value in insertion order is returned.- Parameters:
name
- the name of the header to retrieve.- Returns:
- the first header value or
null
if there is no such header.
-
getAndRemove
Returns the value of a header with the specified name and removes it from this object. If there is more than one value for the specified name, the first value in insertion order is returned.- Parameters:
name
- the name of the header to retrieve.defaultValue
- the default value.- Returns:
- the first header value or
defaultValue
if there is no such header.
-
values
Returns all values for the header with the specified name. -
valuesIterator
Returns all values for the header with the specified name. -
contains
Returnstrue
if a header with thename
exists,false
otherwise.- Parameters:
name
- the header name.- Returns:
true
ifname
exists.
-
contains
Returnstrue
if a header with thename
andvalue
exists,false
otherwise.- Parameters:
name
- the header name.value
- the header value of the header to find.- Returns:
true
if aname
,value
pair exists.
-
containsIgnoreCase
Returnstrue
if a header with thename
andvalue
exists,false
otherwise.Case insensitive compare is done on the value.
- Parameters:
name
- the name of the header to find.value
- the value of the header to find.- Returns:
true
if found.
-
size
int size()Returns the number of headers in this object.- Returns:
- the number of headers in this object.
-
isEmpty
boolean isEmpty()- Returns:
true
ifsize()
equals0
.
-
names
Set<? extends CharSequence> names() -
add
Adds a new header with the specifiedname
andvalue
.- Parameters:
name
- the name of the header.value
- the value of the header.- Returns:
this
.
-
add
Adds new headers with the specifiedname
andvalues
. This method is semantically equivalent to:for (T value : values) { headers.add(name, value); }
- Parameters:
name
- the name of the header.values
- the values of the header.- Returns:
this
.
-
add
Adds new headers with the specifiedname
andvalues
. This method is semantically equivalent to:while (valueItr.hasNext()) { headers.add(name, valueItr.next()); }
- Parameters:
name
- the name of the header.valuesItr
- the values of the header.- Returns:
this
.
-
add
Adds new headers with the specifiedname
andvalues
. This method is semantically equivalent to:for (T value : values) { headers.add(name, value); }
- Parameters:
name
- the name of the header.values
- the values of the header.- Returns:
this
.
-
add
Adds all header names and values ofheaders
to this object.- Parameters:
headers
- the headers to add.- Returns:
this
.
-
set
Sets a header with the specifiedname
andvalue
. Any existing headers with the same name are overwritten.- Parameters:
name
- the name of the header.value
- the value of the header.- Returns:
this
.
-
set
Sets a new header with the specifiedname
andvalues
. This method is equivalent to:headers.remove(name); for (T value : values) { headers.add(name, value); }
- Parameters:
name
- the name of the header.values
- the values of the header.- Returns:
this
.
-
set
Sets a new header with the specifiedname
andvalues
. This method is equivalent to:headers.remove(name); while (valueItr.hasNext()) { headers.add(name, valueItr.next()); }
- Parameters:
name
- the name of the header.valueItr
- the values of the header.- Returns:
this
.
-
set
Sets a header with the specifiedname
andvalues
. Any existing headers with this name are removed. This method is equivalent to:headers.remove(name); for (T value : values) { headers.add(name, value); }
- Parameters:
name
- the name of the header.values
- the values of the header.- Returns:
this
.
-
set
Clears the current header entries and copies all header entries of the specifiedheaders
object.- Parameters:
headers
- the headers object which contains new values.- Returns:
this
.
-
replace
Removes all header names contained inheaders
from this object, and then adds all headers contained inheaders
.- Parameters:
headers
- the headers used to remove names and then add new entries.- Returns:
this
.
-
remove
Removes all headers with the specifiedname
.- Parameters:
name
- the name of the header.- Returns:
true
if at least one entry has been removed.
-
remove
Removes specific value(s) from the specified headername
. If the header has more than one identical values, all of them will be removed.- Parameters:
name
- the name of the header.value
- the value of the header to remove.- Returns:
true
if at least one value has been removed.
-
removeIgnoreCase
Removes specific value(s) from the specified headername
. If the header has more than one identical values, all of them will be removed.Case insensitive compare is done on the value.
- Parameters:
name
- the name of the header.value
- the value of the header to remove.- Returns:
true
if at least one value has been removed.
-
clear
HttpHeaders clear()Removes all headers.- Returns:
this
.
-
iterator
Iterator<Map.Entry<CharSequence,CharSequence>> iterator()- Specified by:
iterator
in interfaceIterable<Map.Entry<CharSequence,
CharSequence>>
-
spliterator
- Specified by:
spliterator
in interfaceIterable<Map.Entry<CharSequence,
CharSequence>>
-
toString
String toString()Returns aString
representation of thisHttpHeaders
. To avoid accidentally logging sensitive information, implementations should be cautious about logging header content and consider usingtoString(BiFunction)
.- Overrides:
toString
in classObject
- Returns:
- a simple
String
representation of thisHttpHeaders
.
-
toString
Builds a string which represents all the content in thisHttpHeaders
in which sensitive headers can be filtered viafilter
.- Parameters:
filter
- a function that accepts the header name and value and returns the filtered value.- Returns:
- string representation of this
HttpHeaders
.
-
getCookie
Gets a cookie identified byname
. If there is more than oneHttpSetCookie
for the specified name, the firstHttpSetCookie
in insertion order is returned.- Parameters:
name
- the cookie-name to look for.- Returns:
- a
HttpSetCookie
identified byname
.
-
getSetCookie
Gets a set-cookie identified byname
. If there is more than oneHttpSetCookie
for the specified name, the firstHttpSetCookie
in insertion order is returned.- Parameters:
name
- the cookie-name to look for.- Returns:
- a
HttpSetCookie
identified byname
.
-
getCookies
Gets all the cookies. -
getCookiesIterator
Iterator<? extends HttpCookiePair> getCookiesIterator()Gets all the cookies. -
getCookies
Gets the cookies with the same name.- Parameters:
name
- the cookie-name of theHttpSetCookie
s to get.- Returns:
- An
Iterable
where all theHttpSetCookie
s have the same name. - See Also:
-
getCookiesIterator
Gets the cookies with the same name.- Parameters:
name
- the cookie-name of theHttpSetCookie
s to get.- Returns:
- An
Iterator
where all theHttpSetCookie
s have the same name. - See Also:
-
getSetCookies
Gets all the set-cookies.- Returns:
- An
Iterable
with all the set-cookies. - See Also:
-
getSetCookiesIterator
Iterator<? extends HttpSetCookie> getSetCookiesIterator()Gets all the set-cookies.- Returns:
- An
Iterator
with all the set-cookies. - See Also:
-
getSetCookies
Gets the set-cookies with the same name.- Parameters:
name
- the cookie-name of theHttpSetCookie
s to get.- Returns:
- An
Iterable
where all theHttpSetCookie
s have the same name. - See Also:
-
getSetCookiesIterator
Gets the set-cookies with the same name.- Parameters:
name
- the cookie-name of theHttpSetCookie
s to get.- Returns:
- An
Iterator
where all theHttpSetCookie
s have the same name. - See Also:
-
getSetCookies
default Iterable<? extends HttpSetCookie> getSetCookies(CharSequence name, CharSequence domain, CharSequence path) Gets the set-cookies with the same name.- Parameters:
name
- the cookie-name of theHttpSetCookie
s to get.domain
- the domain-value of theHttpSetCookie
s to get. This value may be matched according to the Domain Matching algorithm.path
- the path-av of theHttpSetCookie
s to get. This value may be matched according to the Path Matching algorithm.- Returns:
- An
Iterable
where all theHttpSetCookie
s match the parameter values. - See Also:
-
getSetCookiesIterator
Iterator<? extends HttpSetCookie> getSetCookiesIterator(CharSequence name, CharSequence domain, CharSequence path) Gets the set-cookies with the same name.- Parameters:
name
- the cookie-name of theHttpSetCookie
s to get.domain
- the domain-value of theHttpSetCookie
s to get. This value may be matched according to the Domain Matching algorithm.path
- the path-av of theHttpSetCookie
s to get. This value may be matched according to the Path Matching algorithm.- Returns:
- An
Iterator
where all theHttpSetCookie
s match the parameter values. - See Also:
-
addCookie
Adds a cookie.This may result in multiple
HttpCookiePair
s with same name.- Parameters:
cookie
- the cookie to add.- Returns:
this
.
-
addCookie
Adds a cookie with the specifiedname
andvalue
.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.- Parameters:
name
- the name of the cookie.value
- the value of the cookie.- Returns:
this
.
-
addSetCookie
Adds a set-cookie.This may result in multiple
HttpSetCookie
s with same name.- Parameters:
cookie
- the cookie to add.- Returns:
this
.
-
addSetCookie
Adds a set-cookie with the specifiedname
andvalue
.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.- Parameters:
name
- the name of the cookie.value
- the value of the cookie.- Returns:
this
.
-
removeCookies
Removes all cookie identified byname
.- Parameters:
name
- the cookie-name of theHttpSetCookie
s to remove.- Returns:
true
if at least one entry has been removed.
-
removeSetCookies
Removes all set-cookie identified byname
.- Parameters:
name
- the cookie-name of theHttpSetCookie
s to remove.- Returns:
true
if at least one entry has been removed.
-
removeSetCookies
Removes all set-cookie identified byname
.- Parameters:
name
- the cookie-name of theHttpSetCookie
s to remove.domain
- the domain-value of theHttpSetCookie
s to remove. This value may be matched according to the Domain Matching algorithm.path
- the path-av of theHttpSetCookie
s to remove. This value may be matched according to the Path Matching algorithm.- Returns:
true
if at least one entry has been removed.
-