Skip to content

//okhttp/okhttp3/Headers

Headers

[common]\ expect 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.

[jvm]\ actual class Headers : Iterable<Pair<String, String>>

[nonJvm]\ actual class Headers : Iterable<<Error class: unknown class><String, String>>

Types

Name Summary
Builder [common, jvm, nonJvm]
[common]
expect class Builder
[jvm, nonJvm]
actual class Builder
Companion [common, jvm, nonJvm]
[common]
expect object Companion
[jvm, nonJvm]
actual object Companion

Functions

Name Summary
byteCount [jvm, nonJvm]
[jvm]
fun byteCount(): Long
[nonJvm]
fun byteCount(): Long
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.
equals [common]
expect open operator override fun equals(other: Any?): Boolean
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:
[jvm, nonJvm]
[jvm, nonJvm]
actual open operator override fun equals(other: Any?): Boolean
forEach [jvm]
open fun forEach(p0: Consumer<in Pair<String, String>>)
get [common]
expect operator fun get(name: String): String?
Returns the last value corresponding to the specified field, or null.
[jvm, nonJvm]
[jvm, nonJvm]
actual operator fun get(name: String): String?
getDate [jvm]
fun getDate(name: String): Date?
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.
getInstant [jvm]
@IgnoreJRERequirement
fun getInstant(name: String): Instant?
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.
hashCode [jvm, nonJvm]
[jvm]
open override fun hashCode(): Int
[nonJvm]
open override fun hashCode(): Int
iterator [common, jvm, nonJvm]
[common]
expect open operator override fun iterator(): Iterator<Pair<String, String>>
[jvm, nonJvm]
actual open operator override fun iterator(): Iterator<Pair<String, String>>
name [common]
expect fun name(index: Int): String
Returns the field at position.
[jvm, nonJvm]
[jvm, nonJvm]
actual fun name(index: Int): String
names [common]
expect fun names(): Set<String>
Returns an immutable case-insensitive set of header names.
[jvm, nonJvm]
[jvm, nonJvm]
actual fun names(): Set<String>
newBuilder [common, jvm, nonJvm]
[common]
expect fun newBuilder(): Headers.Builder
[jvm, nonJvm]
actual fun newBuilder(): Headers.Builder
spliterator [jvm]
open fun spliterator(): Spliterator<Pair<String, String>>
toMultimap [jvm]
fun toMultimap(): Map<String, List<String>>
toString [common]
expect open override fun toString(): String
Returns header names and values. The names and values are separated by : and each pair is followed by a newline character \n.
[jvm, nonJvm]
[jvm, nonJvm]
actual open override fun toString(): String
value [common]
expect fun value(index: Int): String
Returns the value at index.
[jvm, nonJvm]
[jvm, nonJvm]
actual fun value(index: Int): String
values [common]
expect fun values(name: String): List<String>
Returns an immutable list of the header values for name.
[jvm, nonJvm]
[jvm, nonJvm]
actual fun values(name: String): List<String>

Properties

Name Summary
size [common]
expect val size: Int
Returns the number of field values.
[jvm]
@get:JvmName(name = "size")
actual val size: Int
[nonJvm]
actual val size: Int