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 ofheadersto this object.add(CharSequence name, CharSequence value) Adds a new header with the specifiednameandvalue.add(CharSequence name, CharSequence... values) Adds new headers with the specifiednameandvalues.add(CharSequence name, Iterable<? extends CharSequence> values) Adds new headers with the specifiednameandvalues.default HttpHeadersadd(CharSequence name, Iterator<? extends CharSequence> valuesItr) Adds new headers with the specifiednameandvalues.addCookie(HttpCookiePair cookie) Adds a cookie.default HttpHeadersaddCookie(CharSequence name, CharSequence value) addSetCookie(HttpSetCookie cookie) Adds a set-cookie.default HttpHeadersaddSetCookie(CharSequence name, CharSequence value) clear()Removes all headers.default booleancontains(CharSequence name) Returnstrueif a header with thenameexists,falseotherwise.booleancontains(CharSequence name, CharSequence value) Returnstrueif a header with thenameandvalueexists,falseotherwise.booleancontainsIgnoreCase(CharSequence name, CharSequence value) Returnstrueif a header with thenameandvalueexists,falseotherwise.get(CharSequence name) Returns the value of a header with the specified name.default CharSequenceget(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 CharSequencegetAndRemove(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.booleanisEmpty()iterator()Set<? extends CharSequence>names()Returns aSetof all header names in this object.booleanremove(CharSequence name) Removes all headers with the specifiedname.booleanremove(CharSequence name, CharSequence value) Removes specific value(s) from the specified headername.booleanremoveCookies(CharSequence name) Removes all cookie identified byname.booleanremoveIgnoreCase(CharSequence name, CharSequence value) Removes specific value(s) from the specified headername.booleanremoveSetCookies(CharSequence name) Removes all set-cookie identified byname.booleanremoveSetCookies(CharSequence name, CharSequence domain, CharSequence path) Removes all set-cookie identified byname.default HttpHeadersreplace(HttpHeaders headers) Removes all header names contained inheadersfrom this object, and then adds all headers contained inheaders.default HttpHeadersset(HttpHeaders headers) Clears the current header entries and copies all header entries of the specifiedheadersobject.set(CharSequence name, CharSequence value) Sets a header with the specifiednameandvalue.set(CharSequence name, CharSequence... values) Sets a header with the specifiednameandvalues.set(CharSequence name, Iterable<? extends CharSequence> values) Sets a new header with the specifiednameandvalues.default HttpHeadersset(CharSequence name, Iterator<? extends CharSequence> valueItr) Sets a new header with the specifiednameandvalues.intsize()Returns the number of headers in this object.default Spliterator<Map.Entry<CharSequence,CharSequence>> toString()Returns aStringrepresentation of thisHttpHeaders.default StringtoString(BiFunction<? super CharSequence, ? super CharSequence, CharSequence> filter) Builds a string which represents all the content in thisHttpHeadersin 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.
nullif 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
defaultValueif 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
nullif 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
defaultValueif 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
Returnstrueif a header with thenameexists,falseotherwise.- Parameters:
name- the header name.- Returns:
trueifnameexists.
-
contains
Returnstrueif a header with thenameandvalueexists,falseotherwise.- Parameters:
name- the header name.value- the header value of the header to find.- Returns:
trueif aname,valuepair exists.
-
containsIgnoreCase
Returnstrueif a header with thenameandvalueexists,falseotherwise.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:
trueif found.
-
size
int size()Returns the number of headers in this object.- Returns:
- the number of headers in this object.
-
isEmpty
boolean isEmpty()- Returns:
trueifsize()equals0.
-
names
Set<? extends CharSequence> names() -
add
Adds a new header with the specifiednameandvalue.- Parameters:
name- the name of the header.value- the value of the header.- Returns:
this.
-
add
Adds new headers with the specifiednameandvalues. 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 specifiednameandvalues. 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 specifiednameandvalues. 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 ofheadersto this object.- Parameters:
headers- the headers to add.- Returns:
this.
-
set
Sets a header with the specifiednameandvalue. 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 specifiednameandvalues. 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 specifiednameandvalues. 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 specifiednameandvalues. 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 specifiedheadersobject.- Parameters:
headers- the headers object which contains new values.- Returns:
this.
-
replace
Removes all header names contained inheadersfrom 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:
trueif 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:
trueif 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:
trueif at least one value has been removed.
-
clear
HttpHeaders clear()Removes all headers.- Returns:
this.
-
iterator
Iterator<Map.Entry<CharSequence,CharSequence>> iterator()- Specified by:
iteratorin interfaceIterable<Map.Entry<CharSequence,CharSequence>>
-
spliterator
- Specified by:
spliteratorin interfaceIterable<Map.Entry<CharSequence,CharSequence>>
-
toString
String toString()Returns aStringrepresentation of thisHttpHeaders. To avoid accidentally logging sensitive information, implementations should be cautious about logging header content and consider usingtoString(BiFunction).- Overrides:
toStringin classObject- Returns:
- a simple
Stringrepresentation of thisHttpHeaders.
-
toString
Builds a string which represents all the content in thisHttpHeadersin 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 oneHttpSetCookiefor the specified name, the firstHttpSetCookiein insertion order is returned.- Parameters:
name- the cookie-name to look for.- Returns:
- a
HttpSetCookieidentified byname.
-
getSetCookie
Gets a set-cookie identified byname. If there is more than oneHttpSetCookiefor the specified name, the firstHttpSetCookiein insertion order is returned.- Parameters:
name- the cookie-name to look for.- Returns:
- a
HttpSetCookieidentified 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 theHttpSetCookies to get.- Returns:
- An
Iterablewhere all theHttpSetCookies have the same name. - See Also:
-
getCookiesIterator
Gets the cookies with the same name.- Parameters:
name- the cookie-name of theHttpSetCookies to get.- Returns:
- An
Iteratorwhere all theHttpSetCookies have the same name. - See Also:
-
getSetCookies
Gets all the set-cookies.- Returns:
- An
Iterablewith all the set-cookies. - See Also:
-
getSetCookiesIterator
Iterator<? extends HttpSetCookie> getSetCookiesIterator()Gets all the set-cookies.- Returns:
- An
Iteratorwith all the set-cookies. - See Also:
-
getSetCookies
Gets the set-cookies with the same name.- Parameters:
name- the cookie-name of theHttpSetCookies to get.- Returns:
- An
Iterablewhere all theHttpSetCookies have the same name. - See Also:
-
getSetCookiesIterator
Gets the set-cookies with the same name.- Parameters:
name- the cookie-name of theHttpSetCookies to get.- Returns:
- An
Iteratorwhere all theHttpSetCookies 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 theHttpSetCookies to get.domain- the domain-value of theHttpSetCookies to get. This value may be matched according to the Domain Matching algorithm.path- the path-av of theHttpSetCookies to get. This value may be matched according to the Path Matching algorithm.- Returns:
- An
Iterablewhere all theHttpSetCookies 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 theHttpSetCookies to get.domain- the domain-value of theHttpSetCookies to get. This value may be matched according to the Domain Matching algorithm.path- the path-av of theHttpSetCookies to get. This value may be matched according to the Path Matching algorithm.- Returns:
- An
Iteratorwhere all theHttpSetCookies match the parameter values. - See Also:
-
addCookie
Adds a cookie.This may result in multiple
HttpCookiePairs with same name.- Parameters:
cookie- the cookie to add.- Returns:
this.
-
addCookie
Adds a cookie with the specifiednameandvalue.This may result in multiple
HttpSetCookies 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
HttpSetCookies with same name.- Parameters:
cookie- the cookie to add.- Returns:
this.
-
addSetCookie
Adds a set-cookie with the specifiednameandvalue.This may result in multiple
HttpSetCookies 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 theHttpSetCookies to remove.- Returns:
trueif at least one entry has been removed.
-
removeSetCookies
Removes all set-cookie identified byname.- Parameters:
name- the cookie-name of theHttpSetCookies to remove.- Returns:
trueif at least one entry has been removed.
-
removeSetCookies
Removes all set-cookie identified byname.- Parameters:
name- the cookie-name of theHttpSetCookies to remove.domain- the domain-value of theHttpSetCookies to remove. This value may be matched according to the Domain Matching algorithm.path- the path-av of theHttpSetCookies to remove. This value may be matched according to the Path Matching algorithm.- Returns:
trueif at least one entry has been removed.
-