okarm
04/09/2021, 8:24 PMfinish
a pipeline without worrying about resources?
Simplified use case (Authenticator):
I'm intercepting the HttpReceivePipeline.Before
phase.
For that pipeline the subject is HttpResponse
and the context is HttpClientCall
1. If the subject is Unauthorized, the interceptor refreshes API token under a Mutex.
2. If the token refresh was successful, the interceptor calls finish
and executes a new HttpStatement
, taking the current subject.request
as its base.
val retry: HttpRequestBuilder? = mutex.withLock {
// Build a new request with refreshed credentials
// or return null to proceed normally
}
if (scope.isActive && retry != null) {
finish()
val newResponse = HttpStatement(retry, scope).execute()
proceedWith(newResponse)
}