okhttp / okhttp3 / Headers

Headers

class Headers :Iterable<Pair<String,String>>

The header fields of a single HTTP message. Values are uninterpreted strings; use 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 Builder to create instances.

Types

Name Summary
Builder class Builder

Properties

Name Summary
size Returns the number of field values.val size:Int

Functions

Name Summary
byteCount Returns the number of bytes required to encode these headers using HTTP/1.1. This is also the approximate size of HTTP/2 headers before they are compressed with HPACK. This value is intended to be used as a metric: smaller headers are more efficient to encode and transmit.fun byteCount():Long
equals Returns true if 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:fun equals(other:Any?):Boolean
get Returns the last value corresponding to the specified field, or null.operator fun get(name:String):String?
getDate 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.fun getDate(name:String):Date?
getInstant 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.fun getInstant(name:String):Instant?
hashCode fun hashCode():Int
iterator operator fun iterator():Iterator<Pair<String,String>>
name Returns the field at position.fun name(index:Int):String
names Returns an immutable case-insensitive set of header names.fun names():Set<String>
newBuilder fun newBuilder(): Builder
toMultimap fun toMultimap():Map<String,List<String>>
toString fun toString():String
value Returns the value at index.fun value(index:Int):String
values Returns an immutable list of the header values for name.fun values(name:String):List<String>

Companion Object Functions

Name Summary
headersOf 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.fun headersOf(vararg namesAndValues:String):Headers
toHeaders Returns headers for the header names and values in the Map.funMap<String,String>.toHeaders():Headers