- java.lang.Object
-
- jdk.incubator.http.HttpHeaders
-
public abstract class HttpHeaders extends Object
A read-only view of a set of HTTP headers.
Incubating Feature. Will be removed in a future release.The methods of this class ( that accept a String header name ), and the Map returned by the map method, operate without regard to case when retrieving the header value.
HttpHeaders instances are immutable.
- Since:
- 9
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
HttpHeaders()
Creates an HttpHeaders.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description List<String>
allValues(String name)
Returns an unmodifiable List of all of the values of the given named header.boolean
equals(Object obj)
Tests this HTTP headers instance for equality with the given object.Optional<String>
firstValue(String name)
Returns anOptional
containing the first value of the given named (and possibly multi-valued) header.OptionalLong
firstValueAsLong(String name)
Returns anOptionalLong
containing the first value of the named header field.int
hashCode()
Computes a hash code for this HTTP headers instance.abstract Map<String,List<String>>
map()
Returns an unmodifiable multi Map view of this HttpHeaders.String
toString()
Returns this HTTP headers as a string.
-
-
-
Method Detail
-
firstValue
public Optional<String> firstValue(String name)
Returns anOptional
containing the first value of the given named (and possibly multi-valued) header. If the header is not present, then the returnedOptional
is empty.- Implementation Requirements:
- The default implementation invokes
allValues(name).stream().findFirst()
- Parameters:
name
- the header name- Returns:
- an
Optional<String>
for the first named value
-
firstValueAsLong
public OptionalLong firstValueAsLong(String name)
Returns anOptionalLong
containing the first value of the named header field. If the header is not present, then the Optional is empty. If the header is present but contains a value that does not parse as aLong
value, then an exception is thrown.- Implementation Requirements:
- The default implementation invokes
allValues(name).stream().mapToLong(Long::valueOf).findFirst()
- Parameters:
name
- the header name- Returns:
- an
OptionalLong
- Throws:
NumberFormatException
- if a value is found, but does not parse as a Long
-
allValues
public List<String> allValues(String name)
Returns an unmodifiable List of all of the values of the given named header. Always returns a List, which may be empty if the header is not present.- Implementation Requirements:
- The default implementation invokes, among other things, the
map().get(name)
to retrieve the list of header values. - Parameters:
name
- the header name- Returns:
- a List of String values
-
map
public abstract Map<String,List<String>> map()
Returns an unmodifiable multi Map view of this HttpHeaders.- Returns:
- the Map
-
equals
public final boolean equals(Object obj)
Tests this HTTP headers instance for equality with the given object.If the given object is not an
HttpHeaders
then this method returnsfalse
. Two HTTP headers are equal if each of their corresponding maps are equal.This method satisfies the general contract of the
Object.equals
method.- Overrides:
equals
in classObject
- Parameters:
obj
- the object to which this object is to be compared- Returns:
true
if, and only if, the given object is anHttpHeaders
that is equal to this HTTP headers- See Also:
Object.hashCode()
,HashMap
-
hashCode
public final int hashCode()
Computes a hash code for this HTTP headers instance.The hash code is based upon the components of the HTTP headers map, and satisfies the general contract of the
Object.hashCode
method.- Overrides:
hashCode
in classObject
- Returns:
- the hash-code value for this HTTP headers
- See Also:
Object.equals(java.lang.Object)
,System.identityHashCode(java.lang.Object)
-
-