Prateek Kumar
05/07/2024, 5:29 AMval AuthPlugin = createClientPlugin("AuthPlugin", ::AuthPluginConfig) {
on(Send) { request ->
val originalCall = proceed(request)
val code = originalCall.response.bodyAsText().decodeResponseCode()
return@on if (code == TOKEN_EXPIRE) {
val tokenRefreshRequest = HttpRequestBuilder() //Create Token Refresh request
val newToken = proceed(tokenRefreshRequest).parseToken()
request.headers[DR_TOKEN] = newToken
proceed(request)
} else {
originalCall
}
}
}
But the problem is , ByteReadChannel can only be read once, once i read the response , further layer fails.
Am i going in the right direction or is there any way i can make a copy of ByteReadChannel?Aleksei Tirman [JB]
05/07/2024, 8:16 AMAuthProvider
and use the Auth
plugin (https://ktor.io/docs/client-auth.html)?Prateek Kumar
05/07/2024, 9:34 AMAleksei Tirman [JB]
05/07/2024, 9:48 AMSaveBodyPlugin
which, unfortunately, is only available in the 3.0.0-beta-1
release and 3.0.0
EAP releases.Prateek Kumar
05/07/2024, 9:58 AMPrateek Kumar
05/07/2024, 9:59 AMAleksei Tirman [JB]
05/07/2024, 12:53 PM