-
public final class HeadersThe header fields of a single HTTP message. Values are uninterpreted strings; use
{@code MobonRequest}and{@code MobonResponse}for interpreted headers. This class maintains the order of the header fields within the HTTP message.This class tracks header values line-by-line. A field with multiple comma- separated values on the same line will be treated as a field with a single value by this class. It is the caller's responsibility to detect and split on commas if their field permits multiple values. This simplifies use of single-valued fields whose values routinely contain commas, such as cookies or dates.
This class trims whitespace from values. It never returns values with leading or trailing whitespace.
Instances of this class are immutable. Use Builder to create instances.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public final classHeaders.Builder
-
Method Summary
Modifier and Type Method Description Stringget(String name)Returns the last value corresponding to the specified field, or null. DategetDate(String name)Returns the last value corresponding to the specified field parsed as an HTTP date, or null ifeither the field is absent or cannot be parsed as a date. intsize()Returns the number of field values. Stringname(int index)Returns the field at {@code position}.Stringvalue(int index)Returns the value at {@code index}.Set<String>names()Returns an immutable case-insensitive set of header names. List<String>values(String name)Returns an immutable list of the header values for {@code name}.longbyteCount()Returns the number of bytes required to encode these headers using HTTP/1.1. Headers.BuildernewBuilder()booleanequals(@Nullable() Object other)Returns true if {@code other}is a{@code Headers}object with the same headers, with the samecasing, in the same order.inthashCode()StringtoString()Map<String, List<String>>toMultimap()static Headersof(Array<String> namesAndValues)Returns headers for the alternating header names and values. static Headersof(Map<String, String> headers)Returns headers for the header names and values in the Map. -
-
Method Detail
-
get
@Nullable() String get(String name)
Returns the last value corresponding to the specified field, or null.
-
getDate
@Nullable() Date getDate(String name)
Returns the last value corresponding to the specified field parsed as an HTTP date, or null ifeither the field is absent or cannot be parsed as a date.
-
size
int size()
Returns the number of field values.
-
values
List<String> values(String name)
Returns an immutable list of the header values for
{@code name}.
-
byteCount
long byteCount()
Returns the number of bytes required to encode these headers using HTTP/1.1. This is also theapproximate size of HTTP/2 headers before they are compressed with HPACK. This value isintended to be used as a metric: smaller headers are more efficient to encode and transmit.
-
newBuilder
Headers.Builder newBuilder()
-
equals
boolean equals(@Nullable() Object other)
Returns true if
{@code other}is a{@code Headers}object with the same headers, with the samecasing, in the same order. Note that two headers instances may be semantically equalbut not equal according to this method. In particular, none of the following sets of headersare equal according to this method:
Applications that require semantically equal headers should convert them into a canonical formbefore comparing them for equality.{@code * * 1. Original * Content-Type: text/html * Content-Length: 50 * * 2. Different order * Content-Length: 50 * Content-Type: text/html * * 3. Different case * content-type: text/html * content-length: 50 * * 4. Different values * Content-Type: text/html * Content-Length: 050 * }
-
hashCode
int hashCode()
-
toMultimap
Map<String, List<String>> toMultimap()
-
of
static Headers of(Array<String> namesAndValues)
Returns headers for the alternating header names and values. There must be an even number ofarguments, and they must alternate between header names and values.
-
-
-
-