Package io.servicetalk.http.api
Interface HttpHeaders
-
- All Superinterfaces:
java.lang.Iterable<java.util.Map.Entry<java.lang.CharSequence,java.lang.CharSequence>>
- All Known Implementing Classes:
EmptyHttpHeaders
public interface HttpHeaders extends java.lang.Iterable<java.util.Map.Entry<java.lang.CharSequence,java.lang.CharSequence>>
HTTP Header Fields.All header field names are compared in a case-insensitive manner.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default 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
.default HttpHeaders
add(java.lang.CharSequence name, java.util.Iterator<? extends java.lang.CharSequence> valuesItr)
Adds new headers with the specifiedname
andvalues
.HttpHeaders
addCookie(HttpCookiePair cookie)
Adds a cookie.default HttpHeaders
addCookie(java.lang.CharSequence name, java.lang.CharSequence value)
HttpHeaders
addSetCookie(HttpSetCookie cookie)
Adds a set-cookie.default HttpHeaders
addSetCookie(java.lang.CharSequence name, java.lang.CharSequence value)
HttpHeaders
clear()
Removes all headers.default boolean
contains(java.lang.CharSequence name)
Returnstrue
if a header with thename
exists,false
otherwise.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.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 byname
.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 byname
.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 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
.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.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
.default HttpHeaders
set(java.lang.CharSequence name, java.util.Iterator<? extends java.lang.CharSequence> valueItr)
Sets a new header with the specifiedname
andvalues
.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 aString
representation of thisHttpHeaders
.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 thisHttpHeaders
in which sensitive headers can be filtered viafilter
.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.
-
-
-
Method Detail
-
get
@Nullable java.lang.CharSequence get(java.lang.CharSequence name)
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
default java.lang.CharSequence get(java.lang.CharSequence name, java.lang.CharSequence defaultValue)
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
@Nullable java.lang.CharSequence getAndRemove(java.lang.CharSequence name)
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
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. 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
default java.lang.Iterable<? extends java.lang.CharSequence> values(java.lang.CharSequence name)
Returns all values for the header with the specified name.- 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:
if minimal object allocation is required.
-
valuesIterator
java.util.Iterator<? extends java.lang.CharSequence> valuesIterator(java.lang.CharSequence name)
Returns all values for the header with the specified name.- 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
default boolean contains(java.lang.CharSequence name)
Returnstrue
if a header with thename
exists,false
otherwise.- Parameters:
name
- the header name.- Returns:
true
ifname
exists.
-
contains
boolean contains(java.lang.CharSequence name, java.lang.CharSequence value)
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
boolean containsIgnoreCase(java.lang.CharSequence name, java.lang.CharSequence value)
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
java.util.Set<? extends java.lang.CharSequence> names()
Returns aSet
of all header names in this object. The returnedSet
cannot be modified.- Returns:
- a
Set
of all header names in this object. The returnedSet
cannot be modified.
-
add
HttpHeaders add(java.lang.CharSequence name, java.lang.CharSequence value)
Adds a new header with the specifiedname
andvalue
.- Parameters:
name
- the name of the header.value
- the value of the header.- Returns:
this
.
-
add
HttpHeaders add(java.lang.CharSequence name, java.lang.Iterable<? extends java.lang.CharSequence> values)
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
default HttpHeaders add(java.lang.CharSequence name, java.util.Iterator<? extends java.lang.CharSequence> valuesItr)
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
HttpHeaders add(java.lang.CharSequence name, java.lang.CharSequence... values)
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
HttpHeaders add(HttpHeaders headers)
Adds all header names and values ofheaders
to this object.- Parameters:
headers
- the headers to add.- Returns:
this
.
-
set
HttpHeaders set(java.lang.CharSequence name, java.lang.CharSequence value)
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
HttpHeaders set(java.lang.CharSequence name, java.lang.Iterable<? extends java.lang.CharSequence> values)
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
default HttpHeaders set(java.lang.CharSequence name, java.util.Iterator<? extends java.lang.CharSequence> valueItr)
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
HttpHeaders set(java.lang.CharSequence name, java.lang.CharSequence... values)
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
default HttpHeaders set(HttpHeaders headers)
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
default HttpHeaders replace(HttpHeaders headers)
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
boolean remove(java.lang.CharSequence name)
Removes all headers with the specifiedname
.- Parameters:
name
- the name of the header.- Returns:
true
if at least one entry has been removed.
-
remove
boolean remove(java.lang.CharSequence name, java.lang.CharSequence value)
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
boolean removeIgnoreCase(java.lang.CharSequence name, java.lang.CharSequence value)
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
java.util.Iterator<java.util.Map.Entry<java.lang.CharSequence,java.lang.CharSequence>> iterator()
- Specified by:
iterator
in interfacejava.lang.Iterable<java.util.Map.Entry<java.lang.CharSequence,java.lang.CharSequence>>
-
spliterator
default java.util.Spliterator<java.util.Map.Entry<java.lang.CharSequence,java.lang.CharSequence>> spliterator()
- Specified by:
spliterator
in interfacejava.lang.Iterable<java.util.Map.Entry<java.lang.CharSequence,java.lang.CharSequence>>
-
toString
java.lang.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 classjava.lang.Object
- Returns:
- a simple
String
representation of thisHttpHeaders
.
-
toString
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 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
@Nullable HttpCookiePair getCookie(java.lang.CharSequence name)
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
@Nullable HttpSetCookie getSetCookie(java.lang.CharSequence name)
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
default java.lang.Iterable<? extends HttpCookiePair> getCookies()
Gets all the cookies.- Returns:
- An
Iterable
with all the cookies. - See Also:
if minimal object allocation is required.
-
getCookiesIterator
java.util.Iterator<? extends HttpCookiePair> getCookiesIterator()
Gets all the cookies.- Returns:
- An
Iterator
with all the cookies. - See Also:
if Iterable is preferred, at the expense of more object allocation.
-
getCookies
default java.lang.Iterable<? extends HttpCookiePair> getCookies(java.lang.CharSequence name)
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:
if minimal object allocation is required.
-
getCookiesIterator
java.util.Iterator<? extends HttpCookiePair> getCookiesIterator(java.lang.CharSequence name)
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:
if Iterable is preferred, at the expense of more object allocation.
-
getSetCookies
default java.lang.Iterable<? extends HttpSetCookie> getSetCookies()
Gets all the set-cookies.- Returns:
- An
Iterable
with all the set-cookies. - See Also:
if minimal object allocation is required.
-
getSetCookiesIterator
java.util.Iterator<? extends HttpSetCookie> getSetCookiesIterator()
Gets all the set-cookies.- Returns:
- An
Iterator
with all the set-cookies. - See Also:
if Iterable is preferred, at the expense of more object allocation.
-
getSetCookies
default java.lang.Iterable<? extends HttpSetCookie> getSetCookies(java.lang.CharSequence name)
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:
if minimal object allocation is required.
-
getSetCookiesIterator
java.util.Iterator<? extends HttpSetCookie> getSetCookiesIterator(java.lang.CharSequence name)
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:
if Iterable is preferred, at the expense of more object allocation.
-
getSetCookies
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.- 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:
if minimal object allocation is required.
-
getSetCookiesIterator
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.- 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
HttpHeaders addCookie(HttpCookiePair cookie)
Adds a cookie.This may result in multiple
HttpCookiePair
s with same name.- Parameters:
cookie
- the cookie to add.- Returns:
this
.
-
addCookie
default HttpHeaders addCookie(java.lang.CharSequence name, java.lang.CharSequence value)
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
HttpHeaders addSetCookie(HttpSetCookie cookie)
Adds a set-cookie.This may result in multiple
HttpSetCookie
s with same name.- Parameters:
cookie
- the cookie to add.- Returns:
this
.
-
addSetCookie
default HttpHeaders addSetCookie(java.lang.CharSequence name, java.lang.CharSequence value)
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
boolean removeCookies(java.lang.CharSequence name)
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
boolean removeSetCookies(java.lang.CharSequence name)
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
boolean removeSetCookies(java.lang.CharSequence name, java.lang.CharSequence domain, java.lang.CharSequence path)
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.
-
-