1.2.0
CIO client
Is it possible to set a custom timeout for _request_, not _client_? Something like
client.call("url", timeout = 20) { ... }
For now, I see only feature to set timeout for client:
HttpClient(CIO) {
engine { requestTimeout = 20 }
}
I want to use the same client for long polling and common requests.
Yes, this is sorely needed. A workaround for now appears to be to set a very high client timeout, and then use withTimeout around all calls to specify a lower specific value. This is not very elegant though.
@rocketraman Is it possible to set a high timeout in a mpp way ? I've seen platform specific solution such as:
val client = HttpClient(Apache) {
engine {
/**
* Max time between TCP packets - default 10 seconds.
*/
socketTimeout = 10_000
}
}
But I'd really like to keep my code platform agnostic as much as possible
Sure! It'll be possible to do with the HttpTimeout feature.
Sure! It'll be possible to do with the
HttpTimeoutfeature.
Being a feature, that will presumably not allow per-request timeout specs. Will using withTimeout at the coroutine level then be the preferred approach for specifying per-request timeouts?
not allow per-request timeout
Not extact. The feature will add the extensions to the request builder.
Is there any plan when this feature will be implemented? We have single ktor client instance and we need shorter timeout than 10seconds for some requests. Currently we use withTimeout at coroutine level but it works only in android and not in iOS which prevents us to use it in production.
Since 1.3.1 you can use HttpTimeout feature
Most helpful comment
Since 1.3.1 you can use HttpTimeout feature
https://ktor.io/clients/http-client/features/timeout.html