com.koushikdutta.async.http.libcore
Class RawHeaders

java.lang.Object
  extended by com.koushikdutta.async.http.libcore.RawHeaders

public final class RawHeaders
extends java.lang.Object

The HTTP status and unparsed header fields of a single HTTP message. Values are represented as uninterpreted strings; use 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 Summary
RawHeaders()
           
RawHeaders(RawHeaders copyFrom)
           
 
Method Summary
 void add(java.lang.String fieldName, java.lang.String value)
          Add a field with the specified value.
 void addAll(java.lang.String fieldName, java.util.List<java.lang.String> headerFields)
           
 void addLine(java.lang.String line)
          Add an HTTP header line containing a field name, a literal colon, and a value.
static RawHeaders fromMultimap(java.util.Map<java.lang.String,java.util.List<java.lang.String>> map)
          Creates a new instance from the given map of fields to values.
 java.lang.String get(java.lang.String fieldName)
          Returns the last value corresponding to the specified field, or null.
 RawHeaders getAll(java.util.Set<java.lang.String> fieldNames)
           
 java.lang.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.
 java.lang.String getResponseMessage()
          Returns the HTTP status message or null if it is unknown.
 java.lang.String getStatusLine()
           
 java.lang.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.
 void removeAll(java.lang.String fieldName)
           
 void set(java.lang.String fieldName, java.lang.String value)
          Set a field with the specified value.
 void setStatusLine(java.lang.String statusLine)
          Sets the response status line (like "HTTP/1.0 200 OK") or request line (like "GET / HTTP/1.1").
 java.lang.String toHeaderString()
           
 java.util.Map<java.lang.String,java.util.List<java.lang.String>> toMultimap()
          Returns an immutable map containing each field to its list of values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RawHeaders

public RawHeaders()

RawHeaders

public RawHeaders(RawHeaders copyFrom)
Method Detail

setStatusLine

public void setStatusLine(java.lang.String statusLine)
Sets the response status line (like "HTTP/1.0 200 OK") or request line (like "GET / HTTP/1.1").


getStatusLine

public java.lang.String getStatusLine()

getHttpMinorVersion

public int getHttpMinorVersion()
Returns the status line's HTTP minor version. This returns 0 for HTTP/1.0 and 1 for HTTP/1.1. This returns 1 if the HTTP version is unknown.


getResponseCode

public int getResponseCode()
Returns the HTTP status code or -1 if it is unknown.


getResponseMessage

public java.lang.String getResponseMessage()
Returns the HTTP status message or null if it is unknown.


addLine

public void addLine(java.lang.String line)
Add an HTTP header line containing a field name, a literal colon, and a value.


add

public void add(java.lang.String fieldName,
                java.lang.String value)
Add a field with the specified value.


removeAll

public void removeAll(java.lang.String fieldName)

addAll

public void addAll(java.lang.String fieldName,
                   java.util.List<java.lang.String> headerFields)

set

public void set(java.lang.String fieldName,
                java.lang.String value)
Set a field with the specified value. If the field is not found, it is added. If the field is found, the existing values are replaced.


length

public int length()
Returns the number of field values.


getFieldName

public java.lang.String getFieldName(int index)
Returns the field at position or null if that is out of range.


getValue

public java.lang.String getValue(int index)
Returns the value at index or null if that is out of range.


get

public java.lang.String get(java.lang.String fieldName)
Returns the last value corresponding to the specified field, or null.


getAll

public RawHeaders getAll(java.util.Set<java.lang.String> fieldNames)
Parameters:
fieldNames - a case-insensitive set of HTTP header field names.

toHeaderString

public java.lang.String toHeaderString()

toMultimap

public java.util.Map<java.lang.String,java.util.List<java.lang.String>> toMultimap()
Returns an immutable map containing each field to its list of values. The status line is mapped to null.


fromMultimap

public static RawHeaders fromMultimap(java.util.Map<java.lang.String,java.util.List<java.lang.String>> map)
Creates a new instance from the given map of fields to values. If present, the null field's last element will be used to set the status line.