public final class RawHeaders extends Object
RequestHeaders
and
ResponseHeaders
for interpreted headers. This class maintains the
order of the header fields within the HTTP message.
This class tracks fields 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.
Constructor and Description |
---|
RawHeaders() |
RawHeaders(RawHeaders copyFrom) |
Modifier and Type | Method and Description |
---|---|
void |
add(String fieldName,
String value)
Add a field with the specified value.
|
void |
addAll(String fieldName,
List<String> headerFields) |
void |
addLine(String line)
Add an HTTP header line containing a field name, a literal colon, and a
value.
|
void |
addSpdyRequestHeaders(String method,
String path,
String version,
String host,
String scheme) |
static RawHeaders |
fromBytes(InputStream in)
Parses bytes of a response header from an HTTP transport.
|
static RawHeaders |
fromMultimap(Map<String,List<String>> map,
boolean response)
Creates a new instance from the given map of fields to values.
|
static RawHeaders |
fromNameValueBlock(List<String> nameValueBlock)
Returns headers for a name value block containing a SPDY response.
|
String |
get(String fieldName)
Returns the last value corresponding to the specified field, or null.
|
RawHeaders |
getAll(Set<String> fieldNames) |
String |
getFieldName(int index)
Returns the field at
position or null if that is out of range. |
int |
getHttpMinorVersion()
Returns the status line's HTTP minor version.
|
int |
getResponseCode()
Returns the HTTP status code or -1 if it is unknown.
|
String |
getResponseMessage()
Returns the HTTP status message or null if it is unknown.
|
String |
getStatusLine() |
String |
getValue(int index)
Returns the value at
index or null if that is out of range. |
int |
length()
Returns the number of field values.
|
Set<String> |
names()
Returns an immutable case-insensitive set of header names.
|
static void |
readHeaders(InputStream in,
RawHeaders out)
Reads headers or trailers into
out . |
void |
removeAll(String fieldName) |
void |
set(String fieldName,
String value)
Set a field with the specified value.
|
void |
setRequestLine(String requestLine)
Sets the request line (like "GET / HTTP/1.1").
|
void |
setStatusLine(String statusLine)
Sets the response status line (like "HTTP/1.0 200 OK").
|
byte[] |
toBytes()
Returns bytes of a request header for sending on an HTTP transport.
|
Map<String,List<String>> |
toMultimap(boolean response)
Returns an immutable map containing each field to its list of values.
|
List<String> |
toNameValueBlock()
Returns a list of alternating names and values.
|
List<String> |
values(String name)
Returns an immutable list of the header values for
name . |
public RawHeaders()
public RawHeaders(RawHeaders copyFrom)
public void setRequestLine(String requestLine)
public void setStatusLine(String statusLine) throws IOException
IOException
public void addSpdyRequestHeaders(String method, String path, String version, String host, String scheme)
method
- like "GET", "POST", "HEAD", etc.path
- like "/foo/bar.html"version
- like "HTTP/1.1"host
- like "www.android.com:1234"scheme
- like "https"public String getStatusLine()
public int getHttpMinorVersion()
public int getResponseCode()
public String getResponseMessage()
public void addLine(String line)
public void removeAll(String fieldName)
public void set(String fieldName, String value)
public int length()
public String getFieldName(int index)
position
or null if that is out of range.public String getValue(int index)
index
or null if that is out of range.public String get(String fieldName)
public List<String> values(String name)
name
.public RawHeaders getAll(Set<String> fieldNames)
fieldNames
- a case-insensitive set of HTTP header field names.public byte[] toBytes() throws UnsupportedEncodingException
UnsupportedEncodingException
public static RawHeaders fromBytes(InputStream in) throws IOException
IOException
public static void readHeaders(InputStream in, RawHeaders out) throws IOException
out
.IOException
public Map<String,List<String>> toMultimap(boolean response)
public static RawHeaders fromMultimap(Map<String,List<String>> map, boolean response) throws IOException
IOException
public List<String> toNameValueBlock()
public static RawHeaders fromNameValueBlock(List<String> nameValueBlock) throws IOException
IOException
Copyright © 2014. All rights reserved.