From 02c04ffe738a79486529a33599dc7a9d126a268e Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Wed, 16 Jul 2008 11:45:47 +0000 Subject: [PATCH] Moved the default context initialization code to the DefaultHttpClient#createHttpContext method; replaced synchronized HttpContext impl with a non synchronized one: there is a new instance of HttpContext created for each request, there is no point to synchronize access to it git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@677250 13f79535-47bb-0310-9956-ffa450edef68 --- .../http/impl/client/AbstractHttpClient.java | 14 -------------- .../http/impl/client/DefaultHttpClient.java | 18 ++++++++++++++++-- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/module-client/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java b/module-client/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java index a6cf62715..0c97c5884 100644 --- a/module-client/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java +++ b/module-client/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java @@ -57,7 +57,6 @@ import org.apache.http.client.HttpRequestRetryHandler; import org.apache.http.client.RedirectHandler; import org.apache.http.client.UserTokenHandler; import org.apache.http.client.methods.HttpUriRequest; -import org.apache.http.client.protocol.ClientContext; import org.apache.http.conn.ClientConnectionManager; import org.apache.http.conn.ConnectionKeepAliveStrategy; import org.apache.http.conn.routing.HttpRoutePlanner; @@ -531,19 +530,6 @@ public abstract class AbstractHttpClient implements HttpClient { synchronized (this) { HttpContext defaultContext = createHttpContext(); - defaultContext.setAttribute( - ClientContext.AUTHSCHEME_REGISTRY, - getAuthSchemes()); - defaultContext.setAttribute( - ClientContext.COOKIESPEC_REGISTRY, - getCookieSpecs()); - defaultContext.setAttribute( - ClientContext.COOKIE_STORE, - getCookieStore()); - defaultContext.setAttribute( - ClientContext.CREDS_PROVIDER, - getCredentialsProvider()); - if (context == null) { execContext = defaultContext; } else { diff --git a/module-client/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java b/module-client/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java index f4c3eba1b..b7ad3ebb0 100644 --- a/module-client/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java +++ b/module-client/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java @@ -43,6 +43,7 @@ import org.apache.http.client.UserTokenHandler; import org.apache.http.client.params.AuthPolicy; import org.apache.http.client.params.ClientPNames; import org.apache.http.client.params.CookiePolicy; +import org.apache.http.client.protocol.ClientContext; import org.apache.http.client.protocol.RequestAddCookies; import org.apache.http.client.protocol.RequestDefaultHeaders; import org.apache.http.client.protocol.RequestProxyAuthentication; @@ -70,6 +71,7 @@ import org.apache.http.impl.cookie.RFC2965SpecFactory; import org.apache.http.params.BasicHttpParams; import org.apache.http.params.HttpParams; import org.apache.http.params.HttpProtocolParams; +import org.apache.http.protocol.BasicHttpContext; import org.apache.http.protocol.BasicHttpProcessor; import org.apache.http.protocol.HTTP; import org.apache.http.protocol.HttpContext; @@ -79,7 +81,6 @@ import org.apache.http.protocol.RequestContent; import org.apache.http.protocol.RequestExpectContinue; import org.apache.http.protocol.RequestTargetHost; import org.apache.http.protocol.RequestUserAgent; -import org.apache.http.protocol.SyncBasicHttpContext; import org.apache.http.util.VersionInfo; @@ -196,7 +197,20 @@ public class DefaultHttpClient extends AbstractHttpClient { @Override protected HttpContext createHttpContext() { - return new SyncBasicHttpContext(null); + HttpContext context = new BasicHttpContext(); + context.setAttribute( + ClientContext.AUTHSCHEME_REGISTRY, + getAuthSchemes()); + context.setAttribute( + ClientContext.COOKIESPEC_REGISTRY, + getCookieSpecs()); + context.setAttribute( + ClientContext.COOKIE_STORE, + getCookieStore()); + context.setAttribute( + ClientContext.CREDS_PROVIDER, + getCredentialsProvider()); + return context; }