- 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 protectedHttpHeaders()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.booleanequals(Object obj)Tests this HTTP headers instance for equality with the given object.Optional<String>firstValue(String name)Returns anOptionalcontaining the first value of the given named (and possibly multi-valued) header.OptionalLongfirstValueAsLong(String name)Returns anOptionalLongcontaining the first value of the named header field.inthashCode()Computes a hash code for this HTTP headers instance.abstract Map<String,List<String>>map()Returns an unmodifiable multi Map view of this HttpHeaders.StringtoString()Returns this HTTP headers as a string.
-
-
-
Method Detail
-
firstValue
public Optional<String> firstValue(String name)
Returns anOptionalcontaining the first value of the given named (and possibly multi-valued) header. If the header is not present, then the returnedOptionalis 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 anOptionalLongcontaining 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 aLongvalue, 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
HttpHeadersthen 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.equalsmethod.- Overrides:
equalsin classObject- Parameters:
obj- the object to which this object is to be compared- Returns:
trueif, and only if, the given object is anHttpHeadersthat 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.hashCodemethod.- Overrides:
hashCodein classObject- Returns:
- the hash-code value for this HTTP headers
- See Also:
Object.equals(java.lang.Object),System.identityHashCode(java.lang.Object)
-
-