Args.notNull(request, "HTTP request");
Args.notNull(context, "HTTP context");
final HttpClientContext clientContext = HttpClientContext.adapt(context);
final AuthCache authCache = clientContext.getAuthCache();
if (authCache == null) {
this.log.debug("Auth cache not set in the context");
return;
}
final CredentialsProvider credsProvider = clientContext.getCredentialsProvider();
if (credsProvider == null) {
this.log.debug("Credentials provider not set in the context");
return;
}
final RouteInfo route = clientContext.getHttpRoute();
if (route == null) {
this.log.debug("Route info not set in the context");
return;
}
HttpHost target = clientContext.getTargetHost();
if (target == null) {
this.log.debug("Target host not set in the context");
return;
}
if (target.getPort() < 0) {
target = new HttpHost(
target.getHostName(),
route.getTargetHost().getPort(),
target.getSchemeName());
}
final AuthState targetState = clientContext.getTargetAuthState();
if (targetState != null && targetState.getState() == AuthProtocolState.UNCHALLENGED) {
final AuthScheme authScheme = authCache.get(target);
if (authScheme != null) {
doPreemptiveAuth(target, authScheme, targetState, credsProvider);
}
}
final HttpHost proxy = route.getProxyHost();
final AuthState proxyState = clientContext.getProxyAuthState();
if (proxy != null && proxyState != null && proxyState.getState() == AuthProtocolState.UNCHALLENGED) {
final AuthScheme authScheme = authCache.get(proxy);
if (authScheme != null) {
doPreemptiveAuth(proxy, authScheme, proxyState, credsProvider);
}
}
}