Hey, is it bad idea to send http request while sen...
# ktor
d
Hey, is it bad idea to send http request while sending another http request? My use case: we add an auth token for each request within our system, which we need to update after it expires. I thought I would make a feature that intercept calls and adds auth token, but I also need update token periodically so I thought I could do it from within the interceptor, since I have the http client available there. But I feel like it's a horrible idea :P
g
It’s actually fine IMO
We do this on level of http client
d
Copy code
companion object Feature : HttpClientFeature<Configuration, JWTAuth> {
        override fun install(feature: JWTAuth, scope: HttpClient) {
            scope.requestPipeline.intercept(HttpRequestPipeline.State) {
                if (context.headers.getAll(HttpHeaders.Authorization) != null) return@intercept
                val authToken = fetchNewToken(feature, scope)
                context.headers.append(HttpHeaders.Authorization, authToken)
            }
        }
so it would look like something like this
and I wanted to reuse scope: HttpClient and make a call with it
I am not sure that this is what you do
do you create separate http client to do that?
g
Yes, we have actually 2 httpclients, one for authohired requests another for non-authorized