HttpResponse

An immutable response: status, the URL it came from, headers, the redirect chain that led to it and the body.

Stable Core. Built with the factory HttpResponse(status, url) { headers = ...; redirectChain = ...; body(bytes) }. The body and the chain are copied in and read back as copies, so a response shared by several callers cannot be changed by one of them. Equality is identity. toString() prints the status, the redacted URL, the header names, the body size and the number of redirects, never a header value or the body. A transport maps a status outside 100..599 to TransportFailure.Protocol rather than build a response.

Types

Link copied to clipboard

Collects the optional parts of an HttpResponse. Not thread-safe; use it only inside the factory's lambda.

Properties

Link copied to clipboard

The body's size in bytes.

Link copied to clipboard

The headers; empty when none were set.

Link copied to clipboard

The followed redirects, in order; empty unless redirects were followed.

Link copied to clipboard
val status: Int

The status, in 100..599.

Link copied to clipboard
val url: Url

The URL the response came from: the last hop's URL when redirects were followed.

Functions

Link copied to clipboard

Returns the body.

Link copied to clipboard
open override fun toString(): String

A diagnostic string for logs: status, the url in its redacted form (Url.redacted), the headers' names, the body size and the number of redirects, never a header value or the body. Its format is not part of the API and may change.