Hey, I’m trying to intercept the response and repl...
# ktor
t
Hey, I’m trying to intercept the response and replace it with the response from a new request, but for some reason, it’s proceeding with io.ktor.client.features.observer.DelegatedResponse…
🧵 1
a
Please share you code
t
Copy code
scope.responsePipeline.intercept(HttpResponsePipeline.Receive) { (type, content) ->
        val newRequest =
            HttpRequestBuilder().takeFrom(context.request).apply {
                url {
                    parameters["token"] = newToken
                }
                attributes.put(hasTriedToRefreshTokenKey, true)
            }
        println("TokenAutoRefresh: proceed with new token!")
        val newResponse = HttpResponseContainer(type, scope.request(newRequest))
        proceedWith(newResponse)
}
Logcat is something like this:
Copy code
REQUEST OK // first request
RESPONSE OK // first response
REQUEST OK // new request
RESPONSE OK // new response
 io.ktor.client.call.NoTransformationFoundException: No transformation found: class io.ktor.client.features.observer.DelegatedResponse (Kotlin reflection is not available) -> class ExampleClass (Kotlin reflection is not available)
Is it because the new RequestBuilder has a different executionContext? I can’t change the executionContext though, its’ setter is internal…
a
This is most likely due to this problem KTOR-2822. The
takeFrom
method doesn't copy
executionContext
so you use a new one.
t
Thanks, I tried the workaround, but what I want is an HttpRequestBuilder, not a HttpRequest… I can’t send an HttpRequest to scope.request()