public final class Headers extends Object
Request
and Response 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 Headers.Builder to create instances.
| Modifier and Type | Class and Description |
|---|---|
static class |
Headers.Builder |
| Modifier and Type | Method and Description |
|---|---|
long |
byteCount() |
boolean |
equals(Object other)
Returns true if
other is a Headers object with the same headers, with the same
casing, in the same order. |
String |
get(String name) |
Date |
getDate(String name) |
int |
hashCode() |
String |
name(int index) |
Set<String> |
names() |
Headers.Builder |
newBuilder() |
static Headers |
of(Map<String,String> headers) |
static Headers |
of(String... namesAndValues) |
int |
size() |
Map<String,List<String>> |
toMultimap() |
String |
toString() |
String |
value(int index) |
List<String> |
values(String name) |
public int size()
public String name(int index)
public String value(int index)
public long byteCount()
public Headers.Builder newBuilder()
public boolean equals(Object other)
other is a Headers object with the same headers, with the same
casing, in the same order. Note that two headers instances may be semantically equal
but not equal according to this method. In particular, none of the following sets of headers
are equal according to this method:
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
Applications that require semantically equal headers should convert them into a canonical form before comparing them for equality.
Copyright © 2019. All rights reserved.