:wave: is there any way to change the response he...
# ktor
n
đź‘‹ is there any way to change the response headers? Server is not sending
WWW-Authenticate
on 401, so the Auth plugin is not working properly. I have tried with:
Copy code
client.receivePipeline.intercept(HttpReceivePipeline.Before) { response ->
    if (response.status == HttpStatusCode.Unauthorized && !response.headers.contains(HttpHeaders.WWWAuthenticate)) {
        val headers = buildHeaders {
            appendAll(response.headers)
            append(HttpHeaders.WWWAuthenticate, "Bearer")
        }
        proceedWith(object : HttpResponse() {
            override val headers get() = headers
            // delegate all other properties to original response
        })
    } else {
        proceed()
    }
}
And I can see with the debugger that this is invoked before the header check in Ktor's
Auth
class. But still, the response passed to Auth does not include my header. It seems like the response passed to
proceedWith()
does not replace
call.response
, which is what Auth plugin reads. Any idea?
r
Unfortunately, there is no way to do it now.
receivePipeline
semantics is broken, because its context is
HttpClientCall
that has reference on response, that you can’t update. We will fix it in 2.0.0. For now, you can only fix your backend or copy-paste
Auth
feature so that it doesn’t need
WWW-Authenticate
header. Sorry =(
a
n
What about OkHttp network interceptor? Would that be invoked before Ktor response is parsed?
r
Yes, it will.
n
Great! I'll test this. Thanks for helping 🙏
r