HttpTimeout plugin (previously known as feature) allows you to configure the following timeouts:
request timeout — a time period required to process an HTTP call: from sending a request to receiving a response.
connection timeout — a time period in which a client should establish a connection with a server.
socket timeout — a maximum time of inactivity between two data packets when exchanging data with a server.
You can specify these timeouts for all requests or only specific ones.
HttpTimeout only requires the ktor-client-core artifact and doesn't need any specific dependencies.
HttpTimeout, pass it to the
install function inside a client configuration block:
To configure timeouts, you can use corresponding properties:
requestTimeoutMillis for a request timeout.
connectTimeoutMillis for a connection timeout.
socketTimeoutMillis for a socket timeout.
You can specify timeouts for all requests inside the
install block. The code sample below shows how to set a request timout using
If you need to set a timeout only for a specific request, use the HttpRequestBuilder.timeout property:
Note that timeouts specified for a specific request override global timeouts from the
In a case of a timeout, Ktor throws
HttpTimeout has some limitations for specific engines: