Package com.squareup.okhttp
Class Headers
- java.lang.Object
-
- com.squareup.okhttp.Headers
-
public final class Headers extends Object
The header fields of a single HTTP message. Values are uninterpreted strings; useRequestandResponsefor 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.Builderto create instances.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classHeaders.Builder
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods 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 if either the field is absent or cannot be parsed as a date.Stringname(int index)Returns the field atpositionor null if that is out of range.Set<String>names()Returns an immutable case-insensitive set of header names.Headers.BuildernewBuilder()static Headersof(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 theMap.intsize()Returns the number of field values.Map<String,List<String>>toMultimap()StringtoString()Returns a string containing a concise, human-readable description of this object.Stringvalue(int index)Returns the value atindexor null if that is out of range.List<String>values(String name)Returns an immutable list of the header values forname.
-
-
-
Method Detail
-
get
public String get(String name)
Returns the last value corresponding to the specified field, or null.
-
getDate
public Date getDate(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.
-
size
public int size()
Returns the number of field values.
-
name
public String name(int index)
Returns the field atpositionor null if that is out of range.
-
value
public String value(int index)
Returns the value atindexor null if that is out of range.
-
values
public List<String> values(String name)
Returns an immutable list of the header values forname.
-
newBuilder
public Headers.Builder newBuilder()
-
toString
public String toString()
Description copied from class:ObjectReturns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:getClass().getName() + '@' + Integer.toHexString(hashCode())
See Writing a useful
toStringmethod if you intend implementing your owntoStringmethod.
-
of
public static Headers of(String... namesAndValues)
Returns headers for the alternating header names and values. There must be an even number of arguments, and they must alternate between header names and values.
-
-