Package io.servicetalk.http.api
Class EmptyHttpHeaders
java.lang.Object
io.servicetalk.http.api.EmptyHttpHeaders
- All Implemented Interfaces:
HttpHeaders
,Iterable<Map.Entry<CharSequence,
CharSequence>>
HttpHeaders
which are always empty and does not allow modification.-
Field Summary
Fields -
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
.add
(CharSequence name, Iterator<? extends CharSequence> valuesItr) Adds new headers with the specifiedname
andvalues
.addCookie
(HttpCookiePair cookie) Adds a cookie.addCookie
(CharSequence name, CharSequence value) addSetCookie
(HttpSetCookie cookie) Adds a set-cookie.addSetCookie
(CharSequence name, CharSequence value) clear()
Removes all headers.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.boolean
void
forEach
(Consumer<? super Map.Entry<CharSequence, CharSequence>> action) get
(CharSequence name) Returns the value of a header with the specified name.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.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
.Iterable<? extends HttpCookiePair>
Gets all the cookies.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
.Iterable<? extends HttpSetCookie>
Gets all the set-cookies.Iterable<? extends HttpSetCookie>
getSetCookies
(CharSequence name) Gets the set-cookies with the same name.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.int
hashCode()
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
.replace
(HttpHeaders headers) Removes all header names contained inheaders
from this object, and then adds all headers contained inheaders
.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
.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.toString()
Returns aString
representation of thisHttpHeaders
.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
.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.
-
Field Details
-
INSTANCE
-
-
Method Details
-
get
Description copied from interface:HttpHeaders
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.- Specified by:
get
in interfaceHttpHeaders
- 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
Description copied from interface:HttpHeaders
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.- Specified by:
get
in interfaceHttpHeaders
- 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
Description copied from interface:HttpHeaders
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.- Specified by:
getAndRemove
in interfaceHttpHeaders
- Parameters:
name
- the name of the header to retrieve.- Returns:
- the first header value or
null
if there is no such header.
-
getAndRemove
Description copied from interface:HttpHeaders
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.- Specified by:
getAndRemove
in interfaceHttpHeaders
- 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
Description copied from interface:HttpHeaders
Returns all values for the header with the specified name.- Specified by:
values
in interfaceHttpHeaders
- Parameters:
name
- the name of the header to retrieve.- Returns:
- a
Iterable
of header values or an emptyIterable
if no values are found. - See Also:
-
valuesIterator
Description copied from interface:HttpHeaders
Returns all values for the header with the specified name.- Specified by:
valuesIterator
in interfaceHttpHeaders
- Parameters:
name
- the name of the header to retrieve.- Returns:
- a
Iterator
of header values or an emptyIterator
if no values are found. - See Also:
-
contains
Description copied from interface:HttpHeaders
Returnstrue
if a header with thename
exists,false
otherwise.- Specified by:
contains
in interfaceHttpHeaders
- Parameters:
name
- the header name.- Returns:
true
ifname
exists.
-
contains
Description copied from interface:HttpHeaders
Returnstrue
if a header with thename
andvalue
exists,false
otherwise.- Specified by:
contains
in interfaceHttpHeaders
- Parameters:
name
- the header name.value
- the header value of the header to find.- Returns:
true
if aname
,value
pair exists.
-
containsIgnoreCase
Description copied from interface:HttpHeaders
Returnstrue
if a header with thename
andvalue
exists,false
otherwise.Case insensitive compare is done on the value.
- Specified by:
containsIgnoreCase
in interfaceHttpHeaders
- Parameters:
name
- the name of the header to find.value
- the value of the header to find.- Returns:
true
if found.
-
size
public int size()Description copied from interface:HttpHeaders
Returns the number of headers in this object.- Specified by:
size
in interfaceHttpHeaders
- Returns:
- the number of headers in this object.
-
isEmpty
public boolean isEmpty()Description copied from interface:HttpHeaders
- Specified by:
isEmpty
in interfaceHttpHeaders
- Returns:
true
ifHttpHeaders.size()
equals0
.
-
names
Description copied from interface:HttpHeaders
- Specified by:
names
in interfaceHttpHeaders
- Returns:
- a
Set
of all header names in this object. The returnedSet
cannot be modified.
-
add
Description copied from interface:HttpHeaders
Adds a new header with the specifiedname
andvalue
.- Specified by:
add
in interfaceHttpHeaders
- Parameters:
name
- the name of the header.value
- the value of the header.- Returns:
this
.
-
add
Description copied from interface:HttpHeaders
Adds new headers with the specifiedname
andvalues
. This method is semantically equivalent to:for (T value : values) { headers.add(name, value); }
- Specified by:
add
in interfaceHttpHeaders
- Parameters:
name
- the name of the header.values
- the values of the header.- Returns:
this
.
-
add
Description copied from interface:HttpHeaders
Adds new headers with the specifiedname
andvalues
. This method is semantically equivalent to:while (valueItr.hasNext()) { headers.add(name, valueItr.next()); }
- Specified by:
add
in interfaceHttpHeaders
- Parameters:
name
- the name of the header.valuesItr
- the values of the header.- Returns:
this
.
-
add
Description copied from interface:HttpHeaders
Adds new headers with the specifiedname
andvalues
. This method is semantically equivalent to:for (T value : values) { headers.add(name, value); }
- Specified by:
add
in interfaceHttpHeaders
- Parameters:
name
- the name of the header.values
- the values of the header.- Returns:
this
.
-
add
Description copied from interface:HttpHeaders
Adds all header names and values ofheaders
to this object.- Specified by:
add
in interfaceHttpHeaders
- Parameters:
headers
- the headers to add.- Returns:
this
.
-
set
Description copied from interface:HttpHeaders
Sets a header with the specifiedname
andvalue
. Any existing headers with the same name are overwritten.- Specified by:
set
in interfaceHttpHeaders
- Parameters:
name
- the name of the header.value
- the value of the header.- Returns:
this
.
-
set
Description copied from interface:HttpHeaders
Sets a new header with the specifiedname
andvalues
. This method is equivalent to:headers.remove(name); for (T value : values) { headers.add(name, value); }
- Specified by:
set
in interfaceHttpHeaders
- Parameters:
name
- the name of the header.values
- the values of the header.- Returns:
this
.
-
set
Description copied from interface:HttpHeaders
Sets a new header with the specifiedname
andvalues
. This method is equivalent to:headers.remove(name); while (valueItr.hasNext()) { headers.add(name, valueItr.next()); }
- Specified by:
set
in interfaceHttpHeaders
- Parameters:
name
- the name of the header.valueItr
- the values of the header.- Returns:
this
.
-
set
Description copied from interface:HttpHeaders
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); }
- Specified by:
set
in interfaceHttpHeaders
- Parameters:
name
- the name of the header.values
- the values of the header.- Returns:
this
.
-
set
Description copied from interface:HttpHeaders
Clears the current header entries and copies all header entries of the specifiedheaders
object.- Specified by:
set
in interfaceHttpHeaders
- Parameters:
headers
- the headers object which contains new values.- Returns:
this
.
-
replace
Description copied from interface:HttpHeaders
Removes all header names contained inheaders
from this object, and then adds all headers contained inheaders
.- Specified by:
replace
in interfaceHttpHeaders
- Parameters:
headers
- the headers used to remove names and then add new entries.- Returns:
this
.
-
remove
Description copied from interface:HttpHeaders
Removes all headers with the specifiedname
.- Specified by:
remove
in interfaceHttpHeaders
- Parameters:
name
- the name of the header.- Returns:
true
if at least one entry has been removed.
-
remove
Description copied from interface:HttpHeaders
Removes specific value(s) from the specified headername
. If the header has more than one identical values, all of them will be removed.- Specified by:
remove
in interfaceHttpHeaders
- 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
Description copied from interface:HttpHeaders
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.
- Specified by:
removeIgnoreCase
in interfaceHttpHeaders
- 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
Description copied from interface:HttpHeaders
Removes all headers.- Specified by:
clear
in interfaceHttpHeaders
- Returns:
this
.
-
iterator
- Specified by:
iterator
in interfaceHttpHeaders
- Specified by:
iterator
in interfaceIterable<Map.Entry<CharSequence,
CharSequence>>
-
spliterator
- Specified by:
spliterator
in interfaceHttpHeaders
- Specified by:
spliterator
in interfaceIterable<Map.Entry<CharSequence,
CharSequence>>
-
forEach
- Specified by:
forEach
in interfaceIterable<Map.Entry<CharSequence,
CharSequence>>
-
equals
-
hashCode
public int hashCode() -
toString
Description copied from interface:HttpHeaders
Returns aString
representation of thisHttpHeaders
. To avoid accidentally logging sensitive information, implementations should be cautious about logging header content and consider usingHttpHeaders.toString(BiFunction)
.- Specified by:
toString
in interfaceHttpHeaders
- Overrides:
toString
in classObject
- Returns:
- a simple
String
representation of thisHttpHeaders
.
-
toString
Description copied from interface:HttpHeaders
Builds a string which represents all the content in thisHttpHeaders
in which sensitive headers can be filtered viafilter
.- Specified by:
toString
in interfaceHttpHeaders
- Parameters:
filter
- a function that accepts the header name and value and returns the filtered value.- Returns:
- string representation of this
HttpHeaders
.
-
getCookie
Description copied from interface:HttpHeaders
Gets a cookie identified byname
. If there is more than oneHttpSetCookie
for the specified name, the firstHttpSetCookie
in insertion order is returned.- Specified by:
getCookie
in interfaceHttpHeaders
- Parameters:
name
- the cookie-name to look for.- Returns:
- a
HttpSetCookie
identified byname
.
-
getSetCookie
Description copied from interface:HttpHeaders
Gets a set-cookie identified byname
. If there is more than oneHttpSetCookie
for the specified name, the firstHttpSetCookie
in insertion order is returned.- Specified by:
getSetCookie
in interfaceHttpHeaders
- Parameters:
name
- the cookie-name to look for.- Returns:
- a
HttpSetCookie
identified byname
.
-
getCookies
Description copied from interface:HttpHeaders
Gets all the cookies.- Specified by:
getCookies
in interfaceHttpHeaders
- Returns:
- An
Iterable
with all the cookies. - See Also:
-
getCookiesIterator
Description copied from interface:HttpHeaders
Gets all the cookies.- Specified by:
getCookiesIterator
in interfaceHttpHeaders
- Returns:
- An
Iterator
with all the cookies. - See Also:
-
getCookies
Description copied from interface:HttpHeaders
Gets the cookies with the same name.- Specified by:
getCookies
in interfaceHttpHeaders
- Parameters:
name
- the cookie-name of theHttpSetCookie
s to get.- Returns:
- An
Iterable
where all theHttpSetCookie
s have the same name. - See Also:
-
getCookiesIterator
Description copied from interface:HttpHeaders
Gets the cookies with the same name.- Specified by:
getCookiesIterator
in interfaceHttpHeaders
- Parameters:
name
- the cookie-name of theHttpSetCookie
s to get.- Returns:
- An
Iterator
where all theHttpSetCookie
s have the same name. - See Also:
-
getSetCookies
Description copied from interface:HttpHeaders
Gets all the set-cookies.- Specified by:
getSetCookies
in interfaceHttpHeaders
- Returns:
- An
Iterable
with all the set-cookies. - See Also:
-
getSetCookiesIterator
Description copied from interface:HttpHeaders
Gets all the set-cookies.- Specified by:
getSetCookiesIterator
in interfaceHttpHeaders
- Returns:
- An
Iterator
with all the set-cookies. - See Also:
-
getSetCookies
Description copied from interface:HttpHeaders
Gets the set-cookies with the same name.- Specified by:
getSetCookies
in interfaceHttpHeaders
- Parameters:
name
- the cookie-name of theHttpSetCookie
s to get.- Returns:
- An
Iterable
where all theHttpSetCookie
s have the same name. - See Also:
-
getSetCookiesIterator
Description copied from interface:HttpHeaders
Gets the set-cookies with the same name.- Specified by:
getSetCookiesIterator
in interfaceHttpHeaders
- Parameters:
name
- the cookie-name of theHttpSetCookie
s to get.- Returns:
- An
Iterator
where all theHttpSetCookie
s have the same name. - See Also:
-
getSetCookies
public Iterable<? extends HttpSetCookie> getSetCookies(CharSequence name, CharSequence domain, CharSequence path) Description copied from interface:HttpHeaders
Gets the set-cookies with the same name.- Specified by:
getSetCookies
in interfaceHttpHeaders
- 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
public Iterator<? extends HttpSetCookie> getSetCookiesIterator(CharSequence name, CharSequence domain, CharSequence path) Description copied from interface:HttpHeaders
Gets the set-cookies with the same name.- Specified by:
getSetCookiesIterator
in interfaceHttpHeaders
- 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
Description copied from interface:HttpHeaders
Adds a cookie.This may result in multiple
HttpCookiePair
s with same name.- Specified by:
addCookie
in interfaceHttpHeaders
- Parameters:
cookie
- the cookie to add.- Returns:
this
.
-
addCookie
Description copied from interface:HttpHeaders
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.- Specified by:
addCookie
in interfaceHttpHeaders
- Parameters:
name
- the name of the cookie.value
- the value of the cookie.- Returns:
this
.
-
addSetCookie
Description copied from interface:HttpHeaders
Adds a set-cookie.This may result in multiple
HttpSetCookie
s with same name.- Specified by:
addSetCookie
in interfaceHttpHeaders
- Parameters:
cookie
- the cookie to add.- Returns:
this
.
-
addSetCookie
Description copied from interface:HttpHeaders
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.- Specified by:
addSetCookie
in interfaceHttpHeaders
- Parameters:
name
- the name of the cookie.value
- the value of the cookie.- Returns:
this
.
-
removeCookies
Description copied from interface:HttpHeaders
Removes all cookie identified byname
.- Specified by:
removeCookies
in interfaceHttpHeaders
- Parameters:
name
- the cookie-name of theHttpSetCookie
s to remove.- Returns:
true
if at least one entry has been removed.
-
removeSetCookies
Description copied from interface:HttpHeaders
Removes all set-cookie identified byname
.- Specified by:
removeSetCookies
in interfaceHttpHeaders
- Parameters:
name
- the cookie-name of theHttpSetCookie
s to remove.- Returns:
true
if at least one entry has been removed.
-
removeSetCookies
Description copied from interface:HttpHeaders
Removes all set-cookie identified byname
.- Specified by:
removeSetCookies
in interfaceHttpHeaders
- 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.
-