From eeee0720b573d15aa465944569a9a947b87b5045 Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Mon, 23 Sep 2013 12:27:30 +0000 Subject: [PATCH] HTTPCLIENT-1402: Cache default User-Agent value Contributed by yuexiaojun git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1525568 13f79535-47bb-0310-9956-ffa450edef68 --- RELEASE_NOTES.txt | 3 +++ .../apache/http/impl/client/DefaultHttpClient.java | 10 +--------- .../apache/http/impl/client/HttpClientBuilder.java | 14 ++++++++++---- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt index e3c8457b3..4414027f5 100644 --- a/RELEASE_NOTES.txt +++ b/RELEASE_NOTES.txt @@ -1,6 +1,9 @@ Changes since 4.3 ------------------- +* [HTTPCLIENT-1402] Cache default User-Agent value. + Contributed by yuexiaojun + * [HTTPCLIENT-1398] Fixed invalid OSGi metadata caused by corrupted Maven bundle plugin metadata. Contributed by Oleg Kalnichevski diff --git a/httpclient/src/main/java-deprecated/org/apache/http/impl/client/DefaultHttpClient.java b/httpclient/src/main/java-deprecated/org/apache/http/impl/client/DefaultHttpClient.java index d5baf26e9..d41b76019 100644 --- a/httpclient/src/main/java-deprecated/org/apache/http/impl/client/DefaultHttpClient.java +++ b/httpclient/src/main/java-deprecated/org/apache/http/impl/client/DefaultHttpClient.java @@ -47,7 +47,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.util.VersionInfo; /** * Default implementation of {@link org.apache.http.client.HttpClient} pre-configured @@ -181,14 +180,7 @@ public class DefaultHttpClient extends AbstractHttpClient { HttpProtocolParams.setContentCharset(params, HTTP.DEF_CONTENT_CHARSET.name()); HttpConnectionParams.setTcpNoDelay(params, true); HttpConnectionParams.setSocketBufferSize(params, 8192); - - // determine the release version from packaged version info - final VersionInfo vi = VersionInfo.loadVersionInfo - ("org.apache.http.client", DefaultHttpClient.class.getClassLoader()); - final String release = (vi != null) ? - vi.getRelease() : VersionInfo.UNAVAILABLE; - HttpProtocolParams.setUserAgent(params, - "Apache-HttpClient/" + release + " (java 1.5)"); + HttpProtocolParams.setUserAgent(params, HttpClientBuilder.DEFAULT_USER_AGENT); } /** diff --git a/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java b/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java index 81183e1ee..cb6d890c6 100644 --- a/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java +++ b/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java @@ -198,6 +198,15 @@ public class HttpClientBuilder { private List closeables; + static final String DEFAULT_USER_AGENT; + static { + final VersionInfo vi = VersionInfo.loadVersionInfo + ("org.apache.http.client", HttpClientBuilder.class.getClassLoader()); + final String release = (vi != null) ? + vi.getRelease() : VersionInfo.UNAVAILABLE; + DEFAULT_USER_AGENT = "Apache-HttpClient/" + release + " (java 1.5)"; + } + public static HttpClientBuilder create() { return new HttpClientBuilder(); } @@ -788,10 +797,7 @@ public class HttpClientBuilder { userAgent = System.getProperty("http.agent"); } if (userAgent == null) { - final VersionInfo vi = VersionInfo.loadVersionInfo("org.apache.http.client", - HttpClientBuilder.class.getClassLoader()); - final String release = vi != null ? vi.getRelease() : VersionInfo.UNAVAILABLE; - userAgent = "Apache-HttpClient/" + release + " (java 1.5)"; + userAgent = DEFAULT_USER_AGENT; } }