Hi everyone,
I’m using Ktor with interceptors and facing an issue with the response pipeline. My setup is as follows:
override fun install(
plugin: InterceptorPlugin,
scope: HttpClient,
) {
scope.requestPipeline.intercept(HttpRequestPipeline.Transform) { request ->
userInterceptors.forEach {
it.interceptor.encryptContent(this, request)
}
}
scope.responsePipeline.intercept(HttpResponsePipeline.Receive) { (_, _) ->
userResponseInterceptors.forEach {
it.decrypt(this, plugin)
}
}
}
For end to end encryption, I am using "HttpRequestPipeline.Transform" and ecrypting the request and for decryption i am using "HttpResponsePipeline.Receive"
it is working fine when api succeeds.
The problem I’m encountering is that for every API success, HttpResponsePipeline.Receive is called once, but for every failure, it gets called twice. when this pipeline is called second time then it has empty response and it caused exception because body is already consumed.
Has anyone experienced a similar issue or have any insights on why this might be happening?