Headers

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

Link copied to clipboard
class Builder
Link copied to clipboard
object Companion

Properties

Link copied to clipboard
@get:JvmName(name = "size")
val size: Int

Returns the number of field values.

Functions

Link copied to clipboard

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.

Link copied to clipboard
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:

Link copied to clipboard
open fun forEach(p0: Consumer<in Pair<String, String>>)
Link copied to clipboard
operator fun get(name: String): String?

Returns the last value corresponding to the specified field, or null.

Link copied to clipboard
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.

Link copied to clipboard
@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.

Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
open operator override fun iterator(): Iterator<Pair<String, String>>
Link copied to clipboard
fun name(index: Int): String

Returns the field at position.

Link copied to clipboard
fun names(): Set<String>

Returns an immutable case-insensitive set of header names.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
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.

Link copied to clipboard
fun value(index: Int): String

Returns the value at index.

Link copied to clipboard
fun values(name: String): List<String>

Returns an immutable list of the header values for name.