}
if (context == null) {
throw new IllegalArgumentException("HTTP context may not be null");
}
AuthCache authCache = (AuthCache) context.getAttribute(ClientContext.AUTH_CACHE);
if (authCache == null) {
context.setAttribute(ClientContext.AUTH_CACHE, new BasicAuthCache());
} else {
CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(
ClientContext.CREDS_PROVIDER);
HttpHost target = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
if (target != null) {
AuthScheme authScheme = authCache.get(target);
if (authScheme != null) {
doPreemptiveAuth(
target,
authScheme,
(AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE),
credsProvider);
}
}
HttpHost proxy = (HttpHost) context.getAttribute(ExecutionContext.HTTP_PROXY_HOST);
if (proxy != null) {
AuthScheme authScheme = authCache.get(proxy);
if (authScheme != null) {
doPreemptiveAuth(
proxy,
authScheme,
(AuthState) context.getAttribute(ClientContext.PROXY_AUTH_STATE),