HttpHeaders (Java SE 11 & JDK 11 [ad-hoc build]) (original) (raw)
- java.net.http.HttpHeaders
public abstract class HttpHeaders
extends Object
A read-only view of a set of HTTP headers.
An HttpHeaders
is not created directly, but rather returned from an HttpResponse. Specific HTTP headers can be set forrequests through the one of the request builder'sheaders methods.
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:
11
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 an Optional containing the first value of the given named (and possibly multi-valued) header. OptionalLong firstValueAsLong(String name) Returns an OptionalLong 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. * ### Methods declared in class java.lang.[Object](../../../../java.base/java/lang/Object.html "class in java.lang") `[clone](../../../../java.base/java/lang/Object.html#clone%28%29), [finalize](../../../../java.base/java/lang/Object.html#finalize%28%29), [getClass](../../../../java.base/java/lang/Object.html#getClass%28%29), [notify](../../../../java.base/java/lang/Object.html#notify%28%29), [notifyAll](../../../../java.base/java/lang/Object.html#notifyAll%28%29), [wait](../../../../java.base/java/lang/Object.html#wait%28%29), [wait](../../../../java.base/java/lang/Object.html#wait%28long%29), [wait](../../../../java.base/java/lang/Object.html#wait%28long,int%29)`
Constructor Detail
* #### HttpHeaders protected HttpHeaders() Creates an HttpHeaders.
Method Detail
* #### firstValue public [Optional](../../../../java.base/java/util/Optional.html "class in java.util")<[String](../../../../java.base/java/lang/String.html "class in java.lang")> firstValue([String](../../../../java.base/java/lang/String.html "class in java.lang") name) Returns an [Optional](../../../../java.base/java/util/Optional.html "class in java.util") containing the first value of the given named (and possibly multi-valued) header. If the header is not present, then the returned `Optional` 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](../../../../java.base/java/util/OptionalLong.html "class in java.util") firstValueAsLong([String](../../../../java.base/java/lang/String.html "class in java.lang") name) Returns an [OptionalLong](../../../../java.base/java/util/OptionalLong.html "class in java.util") 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 a `Long` 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](../../../../java.base/java/lang/NumberFormatException.html "class in java.lang")` \- if a value is found, but does not parse as a Long * #### allValues public [List](../../../../java.base/java/util/List.html "interface in java.util")<[String](../../../../java.base/java/lang/String.html "class in java.lang")> allValues([String](../../../../java.base/java/lang/String.html "class in java.lang") 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](../../../../java.base/java/util/Map.html "interface in java.util")<[String](../../../../java.base/java/lang/String.html "class in java.lang"),[List](../../../../java.base/java/util/List.html "interface in java.util")<[String](../../../../java.base/java/lang/String.html "class in java.lang")>> map() Returns an unmodifiable multi Map view of this HttpHeaders. Returns: the Map * #### equals public final boolean equals([Object](../../../../java.base/java/lang/Object.html "class in java.lang") obj) Tests this HTTP headers instance for equality with the given object. If the given object is not an `HttpHeaders` then this method returns `false`. Two HTTP headers are equal if each of their corresponding [maps](#map%28%29) are equal. This method satisfies the general contract of the [Object.equals](../../../../java.base/java/lang/Object.html#equals%28java.lang.Object%29) method. Overrides: `[equals](../../../../java.base/java/lang/Object.html#equals%28java.lang.Object%29)` in class `[Object](../../../../java.base/java/lang/Object.html "class in java.lang")` Parameters: `obj` \- the object to which this object is to be compared Returns: `true` if, and only if, the given object is an ` HttpHeaders` that is equal to this HTTP headers See Also: [Object.hashCode()](../../../../java.base/java/lang/Object.html#hashCode%28%29), [HashMap](../../../../java.base/java/util/HashMap.html "class in java.util") * #### 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](#map%28%29), and satisfies the general contract of the[Object.hashCode](../../../../java.base/java/lang/Object.html#hashCode%28%29) method. Overrides: `[hashCode](../../../../java.base/java/lang/Object.html#hashCode%28%29)` in class `[Object](../../../../java.base/java/lang/Object.html "class in java.lang")` Returns: the hash-code value for this HTTP headers See Also: [Object.equals(java.lang.Object)](../../../../java.base/java/lang/Object.html#equals%28java.lang.Object%29), [System.identityHashCode(java.lang.Object)](../../../../java.base/java/lang/System.html#identityHashCode%28java.lang.Object%29) * #### toString public [String](../../../../java.base/java/lang/String.html "class in java.lang") toString() Returns this HTTP headers as a string. Overrides: `[toString](../../../../java.base/java/lang/Object.html#toString%28%29)` in class `[Object](../../../../java.base/java/lang/Object.html "class in java.lang")` Returns: a string describing the HTTP headers
Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2018, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.
DRAFT 11-internal+0-adhoc.chhegar.open