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
HttpHeaderswhich are always empty and does not allow modification.
-
-
Field Summary
Fields Modifier and Type Field Description static HttpHeadersINSTANCE
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HttpHeadersadd(HttpHeaders headers)Adds all header names and values ofheadersto this object.HttpHeadersadd(java.lang.CharSequence name, java.lang.CharSequence value)Adds a new header with the specifiednameandvalue.HttpHeadersadd(java.lang.CharSequence name, java.lang.CharSequence... values)Adds new headers with the specifiednameandvalues.HttpHeadersadd(java.lang.CharSequence name, java.lang.Iterable<? extends java.lang.CharSequence> values)Adds new headers with the specifiednameandvalues.HttpHeadersaddCookie(HttpCookiePair cookie)Adds a cookie.HttpHeadersaddSetCookie(HttpSetCookie cookie)Adds a set-cookie.HttpHeadersclear()Removes all headers.booleancontains(java.lang.CharSequence name, java.lang.CharSequence value)Returnstrueif a header with thenameandvalueexists,falseotherwise.booleancontainsIgnoreCase(java.lang.CharSequence name, java.lang.CharSequence value)Returnstrueif a header with thenameandvalueexists,falseotherwise.booleanequals(java.lang.Object o)java.lang.CharSequenceget(java.lang.CharSequence name)Returns the value of a header with the specified name.java.lang.CharSequenceget(java.lang.CharSequence name, java.lang.CharSequence defaultValue)Returns the value of a header with the specified name.java.lang.CharSequencegetAndRemove(java.lang.CharSequence name)Returns the value of a header with the specified name and removes it from this object.HttpCookiePairgetCookie(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.HttpSetCookiegetSetCookie(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.inthashCode()booleanisEmpty()java.util.Iterator<java.util.Map.Entry<java.lang.CharSequence,java.lang.CharSequence>>iterator()java.util.Set<? extends java.lang.CharSequence>names()Returns aSetof all header names in this object.booleanremove(java.lang.CharSequence name)Removes all headers with the specifiedname.booleanremove(java.lang.CharSequence name, java.lang.CharSequence value)Removes specific value(s) from the specified headername.booleanremoveCookies(java.lang.CharSequence name)Removes all cookie identified byname.booleanremoveIgnoreCase(java.lang.CharSequence name, java.lang.CharSequence value)Removes specific value(s) from the specified headername.booleanremoveSetCookies(java.lang.CharSequence name)Removes all set-cookie identified byname.booleanremoveSetCookies(java.lang.CharSequence name, java.lang.CharSequence domain, java.lang.CharSequence path)Removes all set-cookie identified byname.HttpHeadersreplace(HttpHeaders headers)Removes all header names contained inheadersfrom this object, and then adds all headers contained inheaders.HttpHeadersset(HttpHeaders headers)Clears the current header entries and copies all header entries of the specifiedheadersobject.HttpHeadersset(java.lang.CharSequence name, java.lang.CharSequence value)Sets a header with the specifiednameandvalue.HttpHeadersset(java.lang.CharSequence name, java.lang.CharSequence... values)Sets a header with the specifiednameandvalues.HttpHeadersset(java.lang.CharSequence name, java.lang.Iterable<? extends java.lang.CharSequence> values)Sets a new header with the specifiednameandvalues.intsize()Returns the number of headers in this object.java.lang.StringtoString()Returns aStringrepresentation of thisHttpHeaders.java.lang.StringtoString(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 thisHttpHeadersin 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:HttpHeadersReturns 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:
getin interfaceHttpHeaders- 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
public java.lang.CharSequence get(java.lang.CharSequence name, java.lang.CharSequence defaultValue)Description copied from interface:HttpHeadersReturns 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:
getin interfaceHttpHeaders- 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
@Nullable public java.lang.CharSequence getAndRemove(java.lang.CharSequence name)
Description copied from interface:HttpHeadersReturns 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:
getAndRemovein interfaceHttpHeaders- Parameters:
name- the name of the header to retrieve.- Returns:
- the first header value or
nullif there is no such header.
-
valuesIterator
public java.util.Iterator<? extends java.lang.CharSequence> valuesIterator(java.lang.CharSequence name)
Description copied from interface:HttpHeadersReturns all values for the header with the specified name.- Specified by:
valuesIteratorin interfaceHttpHeaders- Parameters:
name- the name of the header to retrieve.- Returns:
- a
Iteratorof header values or an emptyIteratorif 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:HttpHeadersReturnstrueif a header with thenameandvalueexists,falseotherwise.- Specified by:
containsin interfaceHttpHeaders- Parameters:
name- the header name.value- the header value of the header to find.- Returns:
trueif aname,valuepair exists.
-
containsIgnoreCase
public boolean containsIgnoreCase(java.lang.CharSequence name, java.lang.CharSequence value)Description copied from interface:HttpHeadersReturnstrueif a header with thenameandvalueexists,falseotherwise.Case insensitive compare is done on the value.
- Specified by:
containsIgnoreCasein interfaceHttpHeaders- Parameters:
name- the name of the header to find.value- the value of the header to find.- Returns:
trueif found.
-
size
public int size()
Description copied from interface:HttpHeadersReturns the number of headers in this object.- Specified by:
sizein interfaceHttpHeaders- Returns:
- the number of headers in this object.
-
isEmpty
public boolean isEmpty()
Description copied from interface:HttpHeaders- Specified by:
isEmptyin interfaceHttpHeaders- Returns:
trueifHttpHeaders.size()equals0.
-
names
public java.util.Set<? extends java.lang.CharSequence> names()
Description copied from interface:HttpHeadersReturns aSetof all header names in this object. The returnedSetcannot be modified.- Specified by:
namesin interfaceHttpHeaders- Returns:
- a
Setof all header names in this object. The returnedSetcannot be modified.
-
add
public HttpHeaders add(java.lang.CharSequence name, java.lang.CharSequence value)
Description copied from interface:HttpHeadersAdds a new header with the specifiednameandvalue.- Specified by:
addin 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:HttpHeadersAdds new headers with the specifiednameandvalues. This method is semantically equivalent to:for (T value : values) { headers.add(name, value); }- Specified by:
addin 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:HttpHeadersAdds new headers with the specifiednameandvalues. This method is semantically equivalent to:for (T value : values) { headers.add(name, value); }- Specified by:
addin 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:HttpHeadersAdds all header names and values ofheadersto this object.- Specified by:
addin 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:HttpHeadersSets a header with the specifiednameandvalue. Any existing headers with the same name are overwritten.- Specified by:
setin 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:HttpHeadersSets a new header with the specifiednameandvalues. This method is equivalent to:headers.remove(name); for (T value : values) { headers.add(name, value); }- Specified by:
setin 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:HttpHeadersSets 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); }- Specified by:
setin 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:HttpHeadersClears the current header entries and copies all header entries of the specifiedheadersobject.- Specified by:
setin interfaceHttpHeaders- Parameters:
headers- the headers object which contains new values.- Returns:
this.
-
replace
public HttpHeaders replace(HttpHeaders headers)
Description copied from interface:HttpHeadersRemoves all header names contained inheadersfrom this object, and then adds all headers contained inheaders.- Specified by:
replacein 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:HttpHeadersRemoves all headers with the specifiedname.- Specified by:
removein interfaceHttpHeaders- Parameters:
name- the name of the header.- Returns:
trueif at least one entry has been removed.
-
remove
public boolean remove(java.lang.CharSequence name, java.lang.CharSequence value)Description copied from interface:HttpHeadersRemoves specific value(s) from the specified headername. If the header has more than one identical values, all of them will be removed.- Specified by:
removein interfaceHttpHeaders- 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
public boolean removeIgnoreCase(java.lang.CharSequence name, java.lang.CharSequence value)Description copied from interface:HttpHeadersRemoves 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:
removeIgnoreCasein interfaceHttpHeaders- 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
public HttpHeaders clear()
Description copied from interface:HttpHeadersRemoves all headers.- Specified by:
clearin interfaceHttpHeaders- Returns:
this.
-
iterator
public java.util.Iterator<java.util.Map.Entry<java.lang.CharSequence,java.lang.CharSequence>> iterator()
- Specified by:
iteratorin interfaceHttpHeaders- Specified by:
iteratorin interfacejava.lang.Iterable<java.util.Map.Entry<java.lang.CharSequence,java.lang.CharSequence>>
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
Description copied from interface:HttpHeadersReturns aStringrepresentation of thisHttpHeaders. To avoid accidentally logging sensitive information, implementations should be cautious about logging header content and consider usingHttpHeaders.toString(BiFunction).- Specified by:
toStringin interfaceHttpHeaders- Overrides:
toStringin classjava.lang.Object- Returns:
- a simple
Stringrepresentation 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:HttpHeadersBuilds a string which represents all the content in thisHttpHeadersin which sensitive headers can be filtered viafilter.- Specified by:
toStringin 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:HttpHeadersGets a cookie identified byname. If there is more than oneHttpSetCookiefor the specified name, the firstHttpSetCookiein insertion order is returned.- Specified by:
getCookiein interfaceHttpHeaders- Parameters:
name- the cookie-name to look for.- Returns:
- a
HttpSetCookieidentified byname.
-
getSetCookie
@Nullable public HttpSetCookie getSetCookie(java.lang.CharSequence name)
Description copied from interface:HttpHeadersGets a set-cookie identified byname. If there is more than oneHttpSetCookiefor the specified name, the firstHttpSetCookiein insertion order is returned.- Specified by:
getSetCookiein interfaceHttpHeaders- Parameters:
name- the cookie-name to look for.- Returns:
- a
HttpSetCookieidentified byname.
-
getCookiesIterator
public java.util.Iterator<? extends HttpCookiePair> getCookiesIterator()
Description copied from interface:HttpHeadersGets all the cookies.- Specified by:
getCookiesIteratorin interfaceHttpHeaders- Returns:
- An
Iteratorwith 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:HttpHeadersGets the cookies with the same name.- Specified by:
getCookiesIteratorin interfaceHttpHeaders- Parameters:
name- the cookie-name of theHttpSetCookies to get.- Returns:
- An
Iteratorwhere all theHttpSetCookies 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:HttpHeadersGets all the set-cookies.- Specified by:
getSetCookiesIteratorin interfaceHttpHeaders- Returns:
- An
Iteratorwith 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:HttpHeadersGets the set-cookies with the same name.- Specified by:
getSetCookiesIteratorin interfaceHttpHeaders- Parameters:
name- the cookie-name of theHttpSetCookies to get.- Returns:
- An
Iteratorwhere all theHttpSetCookies 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:HttpHeadersGets the set-cookies with the same name.- Specified by:
getSetCookiesIteratorin interfaceHttpHeaders- 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:
if Iterable is preferred, at the expense of more object allocation.
-
addCookie
public HttpHeaders addCookie(HttpCookiePair cookie)
Description copied from interface:HttpHeadersAdds a cookie.This may result in multiple
HttpCookiePairs with same name.- Specified by:
addCookiein interfaceHttpHeaders- Parameters:
cookie- the cookie to add.- Returns:
this.
-
addSetCookie
public HttpHeaders addSetCookie(HttpSetCookie cookie)
Description copied from interface:HttpHeadersAdds a set-cookie.This may result in multiple
HttpSetCookies with same name.- Specified by:
addSetCookiein interfaceHttpHeaders- Parameters:
cookie- the cookie to add.- Returns:
this.
-
removeCookies
public boolean removeCookies(java.lang.CharSequence name)
Description copied from interface:HttpHeadersRemoves all cookie identified byname.- Specified by:
removeCookiesin interfaceHttpHeaders- Parameters:
name- the cookie-name of theHttpSetCookies to remove.- Returns:
trueif at least one entry has been removed.
-
removeSetCookies
public boolean removeSetCookies(java.lang.CharSequence name)
Description copied from interface:HttpHeadersRemoves all set-cookie identified byname.- Specified by:
removeSetCookiesin interfaceHttpHeaders- Parameters:
name- the cookie-name of theHttpSetCookies to remove.- Returns:
trueif 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:HttpHeadersRemoves all set-cookie identified byname.- Specified by:
removeSetCookiesin interfaceHttpHeaders- 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.
-
-