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
gildor
10/11/2018, 9:01 AM
It’s actually fine IMO
gildor
10/11/2018, 9:01 AM
We do this on level of http client
d
Dias
10/11/2018, 9:07 AM
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)
}
}
Dias
10/11/2018, 9:07 AM
so it would look like something like this
Dias
10/11/2018, 9:07 AM
and I wanted to reuse scope: HttpClient and make a call with it
Dias
10/11/2018, 9:08 AM
I am not sure that this is what you do
Dias
10/11/2018, 10:20 AM
do you create separate http client to do that?
g
gildor
10/11/2018, 10:26 AM
Yes, we have actually 2 httpclients, one for authohired requests another for non-authorized