Package io.ktor.client.features

Types

DefaultRequest

class DefaultRequest

Feature is used to set request default parameters.

ExpectSuccess

class ExpectSuccess

HttpCallValidator

class HttpCallValidator

Response validator feature is used for validate response and handle response exceptions.

HttpClientFeature

interface HttpClientFeature<out TConfig : Any, TFeature : Any>

Base interface representing a HttpClient feature.

HttpPlainText

class HttpPlainText

HttpClient feature that encodes String request bodies to TextContent and processes the response body as String.

HttpRedirect

class HttpRedirect

HttpClient feature that handles http redirect

HttpRequestTimeoutException

class HttpRequestTimeoutException

This exception is thrown in case request timeout exceeded.

HttpSend

class HttpSend

This is internal feature that is always installed.

HttpTimeout

class HttpTimeout

Client HTTP timeout feature. There are no default values, so default timeouts will be taken from engine configuration or considered as infinite time if engine doesn’t provide them.

Sender

interface Sender

This interface represents a request send pipeline interceptor chain

UserAgent

class UserAgent

Default user-agent feature for HttpClient.

Exceptions

ClientRequestException

class ClientRequestException : ResponseException

Bad client request exception.

RedirectResponseException

class RedirectResponseException : ResponseException

Unhandled redirect exception.

ResponseException

open class ResponseException : IllegalStateException

Base for default response exceptions.

SendCountExceedException

class SendCountExceedException : IllegalStateException

Thrown when too many actual requests were sent during a client call. It could be caused by infinite or too long redirect sequence. Maximum number of requests is limited by HttpSend.maxSendCount

ServerResponseException

class ServerResponseException : ResponseException

Server error exception.

Type Aliases

BadResponseStatusException

typealias BadResponseStatusException = ResponseException

CallExceptionHandler

typealias CallExceptionHandler = suspend (cause: Throwable) -> Unit

Response exception handler method.

HttpSendInterceptor

typealias HttpSendInterceptor = suspend Sender.(HttpClientCall, HttpRequestBuilder) -> HttpClientCall

HttpSend pipeline interceptor function

HttpSendInterceptorBackwardCompatible

typealias HttpSendInterceptorBackwardCompatible = suspend Sender.(HttpClientCall) -> HttpClientCall

HttpSend pipeline interceptor function backward compatible with previous implementation.

ResponseValidator

typealias ResponseValidator = suspend (response: HttpResponse) -> Unit

Response validator method.

Functions

BrowserUserAgent

fun HttpClientConfig<*>.BrowserUserAgent(): Unit

Install UserAgent feature with browser-like user agent.

Charsets

fun HttpClientConfig<*>.Charsets(
    block: Config.() -> Unit
): Unit

Configure client charsets.

ConnectTimeoutException

fun ConnectTimeoutException(
    request: HttpRequestData,
    cause: Throwable? = null
): ConnectTimeoutException
fun ConnectTimeoutException(
    url: String,
    timeout: Long?,
    cause: Throwable? = null
): ConnectTimeoutException

This exception is thrown in case connect timeout exceeded.

CurlUserAgent

fun HttpClientConfig<*>.CurlUserAgent(): Unit

Install UserAgent feature with browser-like user agent.

HttpResponseValidator

fun HttpClientConfig<*>.HttpResponseValidator(
    block: Config.() -> Unit
): Unit

Install HttpCallValidator with block configuration.

SocketTimeoutException

fun SocketTimeoutException(
    request: HttpRequestData,
    cause: Throwable? = null
): SocketTimeoutException

This exception is thrown in case socket timeout (read or write) exceeded.

addDefaultResponseValidation

fun HttpClientConfig<*>.addDefaultResponseValidation(): Unit

Default response validation. Check the response status code in range (0..299).

convertLongTimeoutToIntWithInfiniteAsZero

fun convertLongTimeoutToIntWithInfiniteAsZero(
    timeout: Long
): Int

Convert long timeout in milliseconds to int value. To do that we need to consider HttpTimeout.INFINITE_TIMEOUT_MS as zero and convert timeout value to Int.

convertLongTimeoutToLongWithInfiniteAsZero

fun convertLongTimeoutToLongWithInfiniteAsZero(
    timeout: Long
): Long

Convert long timeout in milliseconds to long value. To do that we need to consider HttpTimeout.INFINITE_TIMEOUT_MS as zero and convert timeout value to Int.

defaultRequest

fun HttpClientConfig<*>.defaultRequest(
    block: HttpRequestBuilder.() -> Unit
): Unit

Set request default parameters.

defaultTransformers

fun HttpClient.defaultTransformers(): Unit

Install default transformers. Usually installed by default so there is no need to use it unless you have disabled it via HttpClientConfig.useDefaultTransformers.

feature

fun <B : Any, F : Any> HttpClient.feature(
    feature: HttpClientFeature<B, F>
): F?

Try to get the feature installed in this client. Returns null if the feature was not previously installed.

get

operator fun <B : Any, F : Any> HttpClient.get(
    feature: HttpClientFeature<B, F>
): F

Find the feature installed in HttpClient.

timeout

fun HttpRequestBuilder.timeout(
    block: HttpTimeoutCapabilityConfiguration.() -> Unit
): Unit

Adds timeout boundaries to the request. Requires HttpTimeout feature to be installed.