in httpclient5/src/main/java/org/apache/hc/client5/http/protocol/RequestAuthCache.java [70:128]
public void process(final HttpRequest request, final EntityDetails entity, final HttpContext context)
throws HttpException, IOException {
Args.notNull(request, "HTTP request");
Args.notNull(context, "HTTP context");
final HttpClientContext clientContext = HttpClientContext.adapt(context);
final String exchangeId = clientContext.getExchangeId();
final AuthCache authCache = clientContext.getAuthCache();
if (authCache == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("{} Auth cache not set in the context", exchangeId);
}
return;
}
final CredentialsProvider credsProvider = clientContext.getCredentialsProvider();
if (credsProvider == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("{} Credentials provider not set in the context", exchangeId);
}
return;
}
final RouteInfo route = clientContext.getHttpRoute();
if (route == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("{} Route info not set in the context", exchangeId);
}
return;
}
final HttpHost target = new HttpHost(request.getScheme(), request.getAuthority());
final AuthExchange targetAuthExchange = clientContext.getAuthExchange(target);
if (targetAuthExchange.getState() == AuthExchange.State.UNCHALLENGED) {
final String pathPrefix = RequestSupport.extractPathPrefix(request);
final AuthScheme authScheme = authCache.get(target, pathPrefix);
if (authScheme != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("{} Re-using cached '{}' auth scheme for {}", exchangeId, authScheme.getName(), target);
}
targetAuthExchange.select(authScheme);
}
}
final HttpHost proxy = route.getProxyHost();
if (proxy != null) {
final AuthExchange proxyAuthExchange = clientContext.getAuthExchange(proxy);
if (proxyAuthExchange.getState() == AuthExchange.State.UNCHALLENGED) {
final AuthScheme authScheme = authCache.get(proxy, null);
if (authScheme != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("{} Re-using cached '{}' auth scheme for {}", exchangeId, authScheme.getName(), proxy);
}
proxyAuthExchange.select(authScheme);
}
}
}
}