Package io.ktor.client.plugins

Types

Link copied to clipboard
class BodyProgress

Plugin that provides observable progress for uploads and downloads

Link copied to clipboard
typealias CallExceptionHandler = suspend (cause: Throwable) -> Unit

Response exception handler method.

Link copied to clipboard
typealias CallRequestExceptionHandler = suspend (cause: Throwable, request: HttpRequest) -> Unit

Response exception handler method. request is null if

Link copied to clipboard
class ClientRequestException(response: HttpResponse, cachedResponseText: String) : ResponseException

Bad client request exception.

Link copied to clipboard

Object for installing io.ktor.util.converters.DataConversion as plugin

Link copied to clipboard
class DefaultRequest

Sets default request parameters. Used to add common headers and URL for a request. Note that trailing slash in base URL and leading slash in request URL are important. The rules to calculate a final URL:

Link copied to clipboard
class HttpCallValidator

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

Link copied to clipboard
interface HttpClientPlugin<out TConfig : Any, TPlugin : Any>

Base interface representing a HttpClient plugin.

Link copied to clipboard
class HttpPlainText

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

Link copied to clipboard
class HttpRedirect

An HttpClient plugin that handles HTTP redirects

Link copied to clipboard
class HttpRequestRetry

A plugin that enables the client to retry failed requests. The default retry policy is 3 retries with exponential delay. Typical usages:

Link copied to clipboard
class HttpRequestTimeoutException(url: String, timeoutMillis: Long?) : IOException

This exception is thrown in case request timeout exceeded.

Link copied to clipboard
class HttpSend

This is an internal plugin that is always installed.

Link copied to clipboard
typealias HttpSendInterceptor = suspend Sender.(HttpRequestBuilder) -> HttpClientCall

HttpSend pipeline interceptor function

Link copied to clipboard
class HttpTimeout

A client's HTTP timeout plugin. There are no default values, so default timeouts are taken from the engine configuration or considered as infinite time if the engine doesn't provide them.

Link copied to clipboard
class RedirectResponseException(response: HttpResponse, cachedResponseText: String) : ResponseException

Unhandled redirect exception.

Link copied to clipboard
open class ResponseException(response: HttpResponse, cachedResponseText: String) : IllegalStateException

Base for default response exceptions.

Link copied to clipboard
typealias ResponseValidator = suspend (response: HttpResponse) -> Unit

Response validator method.

You could throw an exception to fail the response.

Link copied to clipboard
class SendCountExceedException(message: String) : 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

Link copied to clipboard
interface Sender

This interface represents a request send pipeline interceptor chain

Link copied to clipboard
class ServerResponseException(response: HttpResponse, cachedResponseText: String) : ResponseException

Server error exception.

Link copied to clipboard
class UserAgent

Default user-agent plugin for HttpClient.

Functions

Link copied to clipboard
fun HttpClientConfig<*>.addDefaultResponseValidation()

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

Link copied to clipboard
fun HttpClientConfig<*>.BrowserUserAgent()

Install UserAgent plugin with browser-like user agent.

Link copied to clipboard
fun HttpClientConfig<*>.Charsets(block: HttpPlainText.Config.() -> Unit)

Configure client charsets.

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

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.

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.

Link copied to clipboard
fun HttpClientConfig<*>.CurlUserAgent()

Install UserAgent plugin with curl user agent.

Link copied to clipboard
fun HttpClientConfig<*>.defaultRequest(block: DefaultRequest.DefaultRequestBuilder.() -> Unit)

Set default request parameters. See DefaultRequest

Link copied to clipboard
fun HttpClient.defaultTransformers()

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

Link copied to clipboard
fun HttpClientConfig<*>.HttpResponseValidator(block: HttpCallValidator.Config.() -> Unit)

Install HttpCallValidator with block configuration.

Link copied to clipboard
fun HttpRequestBuilder.onDownload(listener: ProgressListener?)

Registers listener to observe download progress.

Link copied to clipboard
fun HttpRequestBuilder.onUpload(listener: ProgressListener?)

Registers listener to observe upload progress.

Link copied to clipboard
fun <B : Any, F : Any> HttpClient.plugin(plugin: HttpClientPlugin<B, F>): F

Returns a plugin installed in HttpClient.

Link copied to clipboard
fun <B : Any, F : Any> HttpClient.pluginOrNull(plugin: HttpClientPlugin<B, F>): F?

Returns a plugin installed in this client. Returns null if the plugin was not previously installed.

Link copied to clipboard
fun HttpRequestBuilder.retry(block: HttpRequestRetry.Configuration.() -> Unit)

Configures the HttpRequestRetry plugin on a per-request level.

Link copied to clipboard
fun SocketTimeoutException(request: HttpRequestData, cause: Throwable? = null): SocketTimeoutException

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

Link copied to clipboard

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

Properties

Link copied to clipboard
var HttpRequestBuilder.expectSuccess: Boolean

Terminate HttpClient.receivePipeline if status code is not successful (>=300).