*Is it safe to just `finish` a pipeline without wo...
# ktor
o
Is it safe to just
finish
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.
Copy code
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)
}
👌 1