https://kotlinlang.org logo
#ktor
Title
# ktor
t

Tiago Nunes

09/30/2021, 2:35 PM
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

Aleksei Tirman [JB]

09/30/2021, 2:36 PM
Please share you code
t

Tiago Nunes

09/30/2021, 2:39 PM
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

Aleksei Tirman [JB]

09/30/2021, 2:44 PM
This is most likely due to this problem KTOR-2822. The
takeFrom
method doesn't copy
executionContext
so you use a new one.
t

Tiago Nunes

09/30/2021, 3:26 PM
Thanks, I tried the workaround, but what I want is an HttpRequestBuilder, not a HttpRequest… I can’t send an HttpRequest to scope.request()
3 Views