Package io.servicetalk.http.api
Class EmptyHttpHeaders
- java.lang.Object
-
- io.servicetalk.http.api.EmptyHttpHeaders
-
- All Implemented Interfaces:
HttpHeaders
,java.lang.Iterable<java.util.Map.Entry<java.lang.CharSequence,java.lang.CharSequence>>
public final class EmptyHttpHeaders extends java.lang.Object implements HttpHeaders
HttpHeaders
which are always empty and does not allow modification.
-
-
Field Summary
Fields Modifier and Type Field Description static HttpHeaders
INSTANCE
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HttpHeaders
add(HttpHeaders headers)
Adds all header names and values ofheaders
to this object.HttpHeaders
add(java.lang.CharSequence name, java.lang.CharSequence value)
Adds a new header with the specifiedname
andvalue
.HttpHeaders
add(java.lang.CharSequence name, java.lang.CharSequence... values)
Adds new headers with the specifiedname
andvalues
.HttpHeaders
add(java.lang.CharSequence name, java.lang.Iterable<? extends java.lang.CharSequence> values)
Adds new headers with the specifiedname
andvalues
.HttpHeaders
addCookie(HttpCookiePair cookie)
Adds a cookie.HttpHeaders
addSetCookie(HttpSetCookie cookie)
Adds a set-cookie.HttpHeaders
clear()
Removes all headers.boolean
contains(java.lang.CharSequence name, java.lang.CharSequence value)
Returnstrue
if a header with thename
andvalue
exists,false
otherwise.boolean
containsIgnoreCase(java.lang.CharSequence name, java.lang.CharSequence value)
Returnstrue
if a header with thename
andvalue
exists,false
otherwise.boolean
equals(java.lang.Object o)
java.lang.CharSequence
get(java.lang.CharSequence name)
Returns the value of a header with the specified name.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.HttpCookiePair
getCookie(java.lang.CharSequence name)
Gets a cookie identified byname
.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 byname
.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.int
hashCode()
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 aSet
of all header names in this object.boolean
remove(java.lang.CharSequence name)
Removes all headers with the specifiedname
.boolean
remove(java.lang.CharSequence name, java.lang.CharSequence value)
Removes specific value(s) from the specified headername
.boolean
removeCookies(java.lang.CharSequence name)
Removes all cookie identified byname
.boolean
removeIgnoreCase(java.lang.CharSequence name, java.lang.CharSequence value)
Removes specific value(s) from the specified headername
.boolean
removeSetCookies(java.lang.CharSequence name)
Removes all set-cookie identified byname
.boolean
removeSetCookies(java.lang.CharSequence name, java.lang.CharSequence domain, java.lang.CharSequence path)
Removes all set-cookie identified byname
.HttpHeaders
replace(HttpHeaders headers)
Removes all header names contained inheaders
from this object, and then adds all headers contained inheaders
.HttpHeaders
set(HttpHeaders headers)
Clears the current header entries and copies all header entries of the specifiedheaders
object.HttpHeaders
set(java.lang.CharSequence name, java.lang.CharSequence value)
Sets a header with the specifiedname
andvalue
.HttpHeaders
set(java.lang.CharSequence name, java.lang.CharSequence... values)
Sets a header with the specifiedname
andvalues
.HttpHeaders
set(java.lang.CharSequence name, java.lang.Iterable<? extends java.lang.CharSequence> values)
Sets a new header with the specifiedname
andvalues
.int
size()
Returns the number of headers in this object.java.lang.String
toString()
Returns aString
representation of thisHttpHeaders
.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 thisHttpHeaders
in which sensitive headers can be filtered viafilter
.java.util.Iterator<? extends java.lang.CharSequence>
valuesIterator(java.lang.CharSequence name)
Returns all values for the header with the specified name.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.servicetalk.http.api.HttpHeaders
add, addCookie, addSetCookie, contains, getAndRemove, getCookies, getCookies, getSetCookies, getSetCookies, getSetCookies, set, spliterator, values
-
-
-
-
Field Detail
-
INSTANCE
public static final HttpHeaders INSTANCE
-
-
Method Detail
-
get
@Nullable public java.lang.CharSequence get(java.lang.CharSequence name)
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
public java.lang.CharSequence get(java.lang.CharSequence name, java.lang.CharSequence defaultValue)
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
@Nullable public java.lang.CharSequence getAndRemove(java.lang.CharSequence name)
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.
-
valuesIterator
public java.util.Iterator<? extends java.lang.CharSequence> valuesIterator(java.lang.CharSequence name)
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:
if Iterable is preferred, at the expense of more object allocation.
-
contains
public boolean contains(java.lang.CharSequence name, java.lang.CharSequence value)
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
public boolean containsIgnoreCase(java.lang.CharSequence name, java.lang.CharSequence value)
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
public java.util.Set<? extends java.lang.CharSequence> names()
Description copied from interface:HttpHeaders
Returns aSet
of all header names in this object. The returnedSet
cannot be modified.- Specified by:
names
in interfaceHttpHeaders
- Returns:
- a
Set
of all header names in this object. The returnedSet
cannot be modified.
-
add
public HttpHeaders add(java.lang.CharSequence name, java.lang.CharSequence value)
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
public HttpHeaders add(java.lang.CharSequence name, java.lang.Iterable<? extends java.lang.CharSequence> values)
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
public HttpHeaders add(java.lang.CharSequence name, java.lang.CharSequence... values)
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
public HttpHeaders add(HttpHeaders headers)
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
public HttpHeaders set(java.lang.CharSequence name, java.lang.CharSequence value)
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
public HttpHeaders set(java.lang.CharSequence name, java.lang.Iterable<? extends java.lang.CharSequence> values)
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
public HttpHeaders set(java.lang.CharSequence name, java.lang.CharSequence... values)
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
public HttpHeaders set(HttpHeaders headers)
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
public HttpHeaders replace(HttpHeaders headers)
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
public boolean remove(java.lang.CharSequence name)
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
public boolean remove(java.lang.CharSequence name, java.lang.CharSequence value)
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
public boolean removeIgnoreCase(java.lang.CharSequence name, java.lang.CharSequence value)
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
public HttpHeaders clear()
Description copied from interface:HttpHeaders
Removes all headers.- Specified by:
clear
in interfaceHttpHeaders
- Returns:
this
.
-
iterator
public java.util.Iterator<java.util.Map.Entry<java.lang.CharSequence,java.lang.CharSequence>> iterator()
- Specified by:
iterator
in interfaceHttpHeaders
- Specified by:
iterator
in interfacejava.lang.Iterable<java.util.Map.Entry<java.lang.CharSequence,java.lang.CharSequence>>
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String 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 classjava.lang.Object
- Returns:
- a simple
String
representation of thisHttpHeaders
.
-
toString
public java.lang.String toString(java.util.function.BiFunction<? super java.lang.CharSequence,? super java.lang.CharSequence,java.lang.CharSequence> filter)
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
@Nullable public HttpCookiePair getCookie(java.lang.CharSequence name)
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
@Nullable public HttpSetCookie getSetCookie(java.lang.CharSequence name)
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
.
-
getCookiesIterator
public java.util.Iterator<? extends HttpCookiePair> getCookiesIterator()
Description copied from interface:HttpHeaders
Gets all the cookies.- Specified by:
getCookiesIterator
in interfaceHttpHeaders
- Returns:
- An
Iterator
with all the cookies. - See Also:
if Iterable is preferred, at the expense of more object allocation.
-
getCookiesIterator
public java.util.Iterator<? extends HttpCookiePair> getCookiesIterator(java.lang.CharSequence name)
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:
if Iterable is preferred, at the expense of more object allocation.
-
getSetCookiesIterator
public java.util.Iterator<? extends HttpSetCookie> 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:
if Iterable is preferred, at the expense of more object allocation.
-
getSetCookiesIterator
public java.util.Iterator<? extends HttpSetCookie> getSetCookiesIterator(java.lang.CharSequence name)
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:
if Iterable is preferred, at the expense of more object allocation.
-
getSetCookiesIterator
public java.util.Iterator<? extends HttpSetCookie> getSetCookiesIterator(java.lang.CharSequence name, java.lang.CharSequence domain, java.lang.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:
if Iterable is preferred, at the expense of more object allocation.
-
addCookie
public HttpHeaders addCookie(HttpCookiePair cookie)
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
.
-
addSetCookie
public HttpHeaders addSetCookie(HttpSetCookie cookie)
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
.
-
removeCookies
public boolean removeCookies(java.lang.CharSequence name)
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
public boolean removeSetCookies(java.lang.CharSequence name)
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
public boolean removeSetCookies(java.lang.CharSequence name, java.lang.CharSequence domain, java.lang.CharSequence path)
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.
-
-