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 the request timeout is exceeded. The request timeout is the time period required to process an HTTP call: from sending a request to receiving a response.

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 plugin that allows you to configure the following timeouts:

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

A plugin that adds a User-Agent header to all requests.

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()

Installs the UserAgent plugin with a 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 the connection timeout is exceeded. It indicates the client took too long to establish a connection with a server.

fun convertLongTimeoutToIntWithInfiniteAsZero(timeout: Long): Int

Converts a 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

Converts 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()

Installs the UserAgent plugin with a 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 the socket timeout (read or write) is exceeded. It indicates the time between two data packets when exchanging data with a server was too long.

Link copied to clipboard

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

Properties

Link copied to clipboard
var HttpRequestBuilder.expectSuccess: Boolean

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