this.log.debug("[exchange: " + state.getId() + "] Connection cannot be kept alive");
}
}
state.setNonReusable();
connManager.releaseConnection();
final AuthState proxyAuthState = localContext.getProxyAuthState();
if (proxyAuthState.getState() == AuthProtocolState.SUCCESS
&& proxyAuthState.getAuthScheme() != null
&& proxyAuthState.getAuthScheme().isConnectionBased()) {
if (this.log.isDebugEnabled()) {
this.log.debug("[exchange: " + state.getId() + "] Resetting proxy auth state");
}
proxyAuthState.reset();
}
final AuthState targetAuthState = localContext.getTargetAuthState();
if (targetAuthState.getState() == AuthProtocolState.SUCCESS
&& targetAuthState.getAuthScheme() != null
&& targetAuthState.getAuthScheme().isConnectionBased()) {
if (this.log.isDebugEnabled()) {
this.log.debug("[exchange: " + state.getId() + "] Resetting target auth state");
}
targetAuthState.reset();
}
}
Object userToken = localContext.getUserToken();
if (userToken == null) {
userToken = this.userTokenHandler.getUserToken(localContext);
localContext.setAttribute(HttpClientContext.USER_TOKEN, userToken);
}
if (state.getFinalResponse() != null) {
final HttpAsyncResponseConsumer<?> responseConsumer = state.getResponseConsumer();
responseConsumer.responseCompleted(localContext);
if (this.log.isDebugEnabled()) {
this.log.debug("[exchange: " + state.getId() + "] Response processed");
}
connManager.releaseConnection();
} else {
if (state.getRedirect() != null) {
final HttpUriRequest redirect = state.getRedirect();
final URI uri = redirect.getURI();
if (this.log.isDebugEnabled()) {
this.log.debug("[exchange: " + state.getId() + "] Redirecting to '" + uri + "'");
}
state.setRedirect(null);
final HttpHost newTarget = URIUtils.extractHost(uri);
if (newTarget == null) {
throw new ProtocolException("Redirect URI does not specify a valid host name: " + uri);
}
// Reset auth states if redirecting to another host
final HttpRoute route = state.getRoute();
if (!route.getTargetHost().equals(newTarget)) {
final AuthState targetAuthState = localContext.getTargetAuthState();
if (this.log.isDebugEnabled()) {
this.log.debug("[exchange: " + state.getId() + "] Resetting target auth state");
}
targetAuthState.reset();
final AuthState proxyAuthState = localContext.getProxyAuthState();
final AuthScheme authScheme = proxyAuthState.getAuthScheme();
if (authScheme != null && authScheme.isConnectionBased()) {
if (this.log.isDebugEnabled()) {
this.log.debug("[exchange: " + state.getId() + "] Resetting proxy auth state");
}
proxyAuthState.reset();
}
}
if (!redirect.headerIterator().hasNext()) {
final HttpRequest original = state.getMainRequest().getOriginal();