Ktor 2.0.3 Help

Intercepting requests using HttpSend

The HttpSend plugin allows you to monitor and retry HTTP calls depending on a response. For instance, you can implement call logging or retry a request if a server returns an error response (with the 4xx or 5xx status code).

The HttpSend plugin doesn't require installation. To use it, pass HttpSend to the HttpClient.plugin function and call the intercept method. The example below shows how to retry a request depending on the response status code:

val client = HttpClient(Apache) client.plugin(HttpSend).intercept { request -> val originalCall = execute(request) if (originalCall.response.status.value !in 100..399) { execute(request) } else { originalCall } }

You can find the full sample here: client-http-send.

Last modified: 28 June 2022