Package com.netflix.zuul.message
Class Headers
java.lang.Object
com.netflix.zuul.message.Headers
An abstraction over a collection of http headers. Allows multiple headers with same name, and header names are
compared case insensitively.
There are methods for getting and setting headers by String AND by HeaderName. When possible, use the HeaderName
variants and cache the HeaderName instances somewhere, to avoid case-insensitive String comparisons.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(HeaderName headerName, String value) Adds the name and value to the headers.void
Adds the name and value to the headers.void
addAndValidate
(HeaderName headerName, String value) Adds the name and value to the headers and validatevoid
addAndValidate
(String headerName, String value) Adds the name and value to the headers and validate.void
addIfValid
(HeaderName headerName, String value) Adds the name and value to the headers if validvoid
addIfValid
(String headerName, String value) Adds the name and value to the headers if validboolean
contains
(HeaderName headerName) Returns if there is a header entry that matches the given name.boolean
contains
(HeaderName headerName, String value) Returns if there is a header entry that matches the given name and value.boolean
Returns if there is a header entry that matches the given name.boolean
Returns if there is a header entry that matches the given name and value.static Headers
entries()
Returns the collection of headers.boolean
Equality on headers is not clearly defined, but this method makes an attempt to do so.void
forEachNormalised
(BiConsumer<? super String, ? super String> entryConsumer) Iterates over the header entries with the given consumer.getAll
(HeaderName headerName) Returns all header values associated with the name.Returns all header values associated with the name.getFirst
(HeaderName headerName) Get the first value found for this key even if there are multiple.getFirst
(HeaderName headerName, String defaultValue) Get the first value found for this key even if there are multiple.Get the first value found for this key even if there are multiple.Get the first value found for this key even if there are multiple.int
hashCode()
This method should only be used for testing, as it is expensive to call.keySet()
Returns a set of header names found in this headers object.void
Adds all the headers into this headers object.remove
(HeaderName headerName) Removes the header entries that match the given header name, and returns them as a list.Removes the header entries that match the given header name, and returns them as a list.boolean
removeIf
(Predicate<? super Map.Entry<HeaderName, String>> filter) Removes all header entries that match the given predicate.void
set
(HeaderName headerName, String value) Replace any/all entries with this key, with this single entry.void
Replace any/all entries with this key, with this single entry.void
setAndValidate
(HeaderName headerName, String value) Replace any/all entries with this key, with this single entry and validate.void
setAndValidate
(String headerName, String value) Replace any/all entries with this key, with this single entry and validate.boolean
setIfAbsent
(HeaderName headerName, String value) Adds the name and value to the headers, except if the name is already present.boolean
setIfAbsent
(String headerName, String value) Adds the name and value to the headers, except if the name is already present.boolean
setIfAbsentAndValid
(HeaderName headerName, String value) Validates and adds the name and value to the headers, except if the name is already present.boolean
setIfAbsentAndValid
(String headerName, String value) Validates and adds the name and value to the headers, except if the name is already present.void
setIfValid
(HeaderName headerName, String value) Replace any/all entries with this key, with this single entry if the key and entry are valid.void
setIfValid
(String headerName, String value) Replace any/all entries with this key, with this single entry if the key and entry are valid.int
size()
Returns the number of header entries.toString()
This is used for debugging.
-
Constructor Details
-
Headers
public Headers() -
Headers
public Headers(int initialSize)
-
-
Method Details
-
copyOf
-
getFirst
Get the first value found for this key even if there are multiple. If none, then returnnull
. -
getFirst
Get the first value found for this key even if there are multiple. If none, then returnnull
. -
getFirst
Get the first value found for this key even if there are multiple. If none, then return the specified defaultValue. -
getFirst
Get the first value found for this key even if there are multiple. If none, then return the specified defaultValue. -
getAll
Returns all header values associated with the name. -
getAll
Returns all header values associated with the name. -
forEachNormalised
Iterates over the header entries with the given consumer. The first argument will be the normalised header name as returned byHeaderName.getNormalised()
. The second argument will be the value. Do not modify the headers during iteration. -
set
Replace any/all entries with this key, with this single entry. If value isnull
, then not added, but any existing header of same name is removed. -
set
Replace any/all entries with this key, with this single entry. If value isnull
, then not added, but any existing header of same name is removed. -
setAndValidate
Replace any/all entries with this key, with this single entry and validate. If value isnull
, then not added, but any existing header of same name is removed.- Throws:
ZuulException
- on invalid name or value
-
setIfValid
Replace any/all entries with this key, with this single entry if the key and entry are valid. If value isnull
, then not added, but any existing header of same name is removed. -
setIfValid
Replace any/all entries with this key, with this single entry if the key and entry are valid. If value isnull
, then not added, but any existing header of same name is removed. -
setAndValidate
Replace any/all entries with this key, with this single entry and validate. If value isnull
, then not added, but any existing header of same name is removed.- Throws:
ZuulException
- on invalid name or value
-
setIfAbsent
Adds the name and value to the headers, except if the name is already present. Unlikeset(String, String)
, this method does not accept anull
value.- Returns:
- if the value was successfully added.
-
setIfAbsent
Adds the name and value to the headers, except if the name is already present. Unlikeset(HeaderName, String)
, this method does not accept anull
value.- Returns:
- if the value was successfully added.
-
setIfAbsentAndValid
Validates and adds the name and value to the headers, except if the name is already present. Unlikeset(String, String)
, this method does not accept anull
value.- Returns:
- if the value was successfully added.
-
setIfAbsentAndValid
Validates and adds the name and value to the headers, except if the name is already present. Unlikeset(HeaderName, String)
, this method does not accept anull
value.- Returns:
- if the value was successfully added.
-
add
Adds the name and value to the headers. -
add
Adds the name and value to the headers. -
addAndValidate
Adds the name and value to the headers and validate.- Throws:
ZuulException
- on invalid name or value
-
addAndValidate
Adds the name and value to the headers and validate- Throws:
ZuulException
- on invalid name or value
-
addIfValid
Adds the name and value to the headers if valid -
addIfValid
Adds the name and value to the headers if valid -
putAll
Adds all the headers into this headers object. -
remove
Removes the header entries that match the given header name, and returns them as a list. -
remove
Removes the header entries that match the given header name, and returns them as a list. -
removeIf
Removes all header entries that match the given predicate. Do not access the header list from inside thePredicate.test(T)
body.- Returns:
- if any elements were removed.
-
entries
Returns the collection of headers. -
keySet
Returns a set of header names found in this headers object. If there are duplicate header names, the first one present takes precedence. -
contains
Returns if there is a header entry that matches the given name. -
contains
Returns if there is a header entry that matches the given name. -
contains
Returns if there is a header entry that matches the given name and value. -
contains
Returns if there is a header entry that matches the given name and value. -
size
public int size()Returns the number of header entries. -
hashCode
public int hashCode()This method should only be used for testing, as it is expensive to call. -
equals
Equality on headers is not clearly defined, but this method makes an attempt to do so. This method should only be used for testing, as it is expensive to call. Two headers object are considered equal if they have the same, normalized header names, and have the corresponding header values in the same order. -
toString
This is used for debugging. It is fairly expensive to construct, so don't call it on a hot path.
-