public final class Headers
extends java.lang.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 |
---|---|
java.lang.String |
get(java.lang.String name)
Returns the last value corresponding to the specified field, or null.
|
java.util.Date |
getDate(java.lang.String name)
Returns the last value corresponding to the specified field parsed as an
HTTP date, or null if either the field is absent or cannot be parsed as a
date.
|
java.lang.String |
name(int index)
Returns the field at
position or null if that is out of range. |
java.util.Set<java.lang.String> |
names()
Returns an immutable case-insensitive set of header names.
|
Headers.Builder |
newBuilder() |
static Headers |
of(java.lang.String... namesAndValues)
Returns headers for the alternating header names and values.
|
int |
size()
Returns the number of field values.
|
java.lang.String |
toString() |
java.lang.String |
value(int index)
Returns the value at
index or null if that is out of range. |
java.util.List<java.lang.String> |
values(java.lang.String name)
Returns an immutable list of the header values for
name . |
public java.lang.String get(java.lang.String name)
public java.util.Date getDate(java.lang.String name)
public int size()
public java.lang.String name(int index)
position
or null if that is out of range.public java.lang.String value(int index)
index
or null if that is out of range.public java.util.Set<java.lang.String> names()
public java.util.List<java.lang.String> values(java.lang.String name)
name
.public Headers.Builder newBuilder()
public java.lang.String toString()
toString
in class java.lang.Object
public static Headers of(java.lang.String... namesAndValues)
Copyright © 2014. All Rights Reserved.