From 1ba8a897f3a3006dfea6bb8024c97998752783b8 Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Thu, 15 May 2014 07:52:12 +0000 Subject: [PATCH] HTTPCLIENT-1508: use actual JRE version when generating default User-Agent header git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1594805 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/http/impl/client/DefaultHttpClient.java | 4 +++- .../apache/http/impl/client/HttpClientBuilder.java | 14 +++----------- 2 files changed, 6 insertions(+), 12 deletions(-) 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 d41b76019..fa4f900fb 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,6 +47,7 @@ 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 @@ -180,7 +181,8 @@ public class DefaultHttpClient extends AbstractHttpClient { HttpProtocolParams.setContentCharset(params, HTTP.DEF_CONTENT_CHARSET.name()); HttpConnectionParams.setTcpNoDelay(params, true); HttpConnectionParams.setSocketBufferSize(params, 8192); - HttpProtocolParams.setUserAgent(params, HttpClientBuilder.DEFAULT_USER_AGENT); + HttpProtocolParams.setUserAgent(params, VersionInfo.getUserAgent("Apache-HttpClient", + "org.apache.http.client", DefaultHttpClient.class)); } /** 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 aff837d74..187d35ffd 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 @@ -35,8 +35,8 @@ import java.util.Collection; import java.util.Collections; import java.util.LinkedList; import java.util.List; -import java.util.concurrent.TimeUnit; import java.util.Map; +import java.util.concurrent.TimeUnit; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSocketFactory; @@ -209,15 +209,6 @@ 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(); } @@ -864,7 +855,8 @@ public class HttpClientBuilder { userAgentCopy = System.getProperty("http.agent"); } if (userAgentCopy == null) { - userAgentCopy = DEFAULT_USER_AGENT; + userAgentCopy = VersionInfo.getUserAgent("Apache-HttpClient", + "org.apache.http.client", getClass()); } }