HTTPCLIENT-1107: auth framework redesign

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1175377 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2011-09-25 12:25:07 +00:00
parent e5d83200fd
commit c4d1599bd0
1 changed files with 9 additions and 0 deletions

View File

@ -40,6 +40,8 @@ import org.apache.http.auth.AuthScheme;
import org.apache.http.auth.AuthState; import org.apache.http.auth.AuthState;
import org.apache.http.client.AuthCache; import org.apache.http.client.AuthCache;
import org.apache.http.client.params.AuthPolicy; import org.apache.http.client.params.AuthPolicy;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.impl.client.BasicAuthCache; import org.apache.http.impl.client.BasicAuthCache;
import org.apache.http.protocol.ExecutionContext; import org.apache.http.protocol.ExecutionContext;
import org.apache.http.protocol.HttpContext; import org.apache.http.protocol.HttpContext;
@ -75,6 +77,13 @@ public class ResponseAuthCache implements HttpResponseInterceptor {
AuthState targetState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE); AuthState targetState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
if (target != null && targetState != null) { if (target != null && targetState != null) {
if (isCachable(targetState)) { if (isCachable(targetState)) {
if (target.getPort() < 0) {
SchemeRegistry schemeRegistry = (SchemeRegistry) context.getAttribute(
ClientContext.SCHEME_REGISTRY);
Scheme scheme = schemeRegistry.getScheme(target);
target = new HttpHost(target.getHostName(),
scheme.resolvePort(target.getPort()), target.getSchemeName());
}
if (authCache == null) { if (authCache == null) {
authCache = new BasicAuthCache(); authCache = new BasicAuthCache();
context.setAttribute(ClientContext.AUTH_CACHE, authCache); context.setAttribute(ClientContext.AUTH_CACHE, authCache);