ktor-client-core / io.ktor.client.statement / DefaultHttpResponse

DefaultHttpResponse

class DefaultHttpResponse : HttpResponse

Constructors

<init>

DefaultHttpResponse(call: HttpClientCall, responseData: HttpResponseData)

Properties

call

val call: HttpClientCall

The associated HttpClientCall containing both the underlying HttpClientCall.request and HttpClientCall.response.

content

val content: ByteReadChannel

Unmodified ByteReadChannel with the raw payload of the response.

coroutineContext

val coroutineContext: <ERROR CLASS>

headers

val headers: Headers

requestTime

val requestTime: GMTDate

GMTDate of the request start.

responseTime

val responseTime: GMTDate

GMTDate of the response start.

status

val status: HttpStatusCode

The HttpStatusCode returned by the server. It includes both, the HttpStatusCode.description and the HttpStatusCode.value (code).

version

val version: HttpProtocolVersion

HTTP version. Usually HttpProtocolVersion.HTTP_1_1 or HttpProtocolVersion.HTTP_2_0.

Inherited Functions

toString

open fun toString(): String

Extension Properties

request

val HttpResponse.request: HttpRequest

HttpRequest associated with this response.

Extension Functions

body

suspend fun <T> HttpResponse.body(): T

Tries to receive the payload of the response as an specific type T.

bodyAsChannel

suspend fun HttpResponse.bodyAsChannel(): ByteReadChannel

Read the HttpResponse.content as a ByteReadChannel.

bodyAsText

suspend fun HttpResponse.bodyAsText(fallbackCharset: <ERROR CLASS> = Charsets.UTF_8): String

Read the HttpResponse.content as a String. You can pass an optional charset to specify a charset in the case no one is specified as part of the Content-Type response. If no charset specified either as parameter or as part of the response, io.ktor.client.features.HttpPlainText settings will be used.

discardRemaining

suspend fun HttpResponse.discardRemaining(): Unit

Efficiently discards the remaining bytes of HttpResponse.content.

mapEngineExceptions

fun CoroutineScope.mapEngineExceptions(input: ByteReadChannel, request: HttpRequestData): ByteReadChannel

Returns ByteReadChannel with ByteChannel.close handler that returns SocketTimeoutException instead of SocketTimeoutException.

fun CoroutineScope.mapEngineExceptions(output: ByteWriteChannel, request: HttpRequestData): ByteWriteChannel

Returns ByteWriteChannel with ByteChannel.close handler that returns SocketTimeoutException instead of SocketTimeoutException.

readBytes

suspend fun HttpResponse.readBytes(count: Int): ByteArray

Exactly reads count bytes of the HttpResponse.content.

suspend fun HttpResponse.readBytes(): ByteArray

Reads the whole HttpResponse.content if Content-Length was specified. Otherwise it just reads one byte.