From f04d81e3026c143f2764b10c2f83f85f5c1b3d3c Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Mon, 24 Dec 2018 00:18:11 +0100 Subject: [PATCH] [HTTPCLIENT-1952] Allow default User Agent to be disabled --- .../apache/http/impl/client/HttpClientBuilder.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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 3a7c5613b..1f78e0efa 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 @@ -205,6 +205,7 @@ public class HttpClientBuilder { private boolean cookieManagementDisabled; private boolean authCachingDisabled; private boolean connectionStateDisabled; + private boolean defaultUserAgentDisabled; private int maxConnTotal = 0; private int maxConnPerRoute = 0; @@ -864,6 +865,16 @@ public class HttpClientBuilder { return this; } + /** + * Disables the default user agent set by this builder if none has been provided by the user. + * + * @since 4.5.7 + */ + public final HttpClientBuilder disableDefaultUserAgent() { + this.defaultUserAgentDisabled = true; + return this; + } + /** * Produces an instance of {@link ClientExecChain} to be used as a main exec. *

@@ -1042,7 +1053,7 @@ public class HttpClientBuilder { if (systemProperties) { userAgentCopy = System.getProperty("http.agent"); } - if (userAgentCopy == null) { + if (userAgentCopy == null && !defaultUserAgentDisabled) { userAgentCopy = VersionInfo.getUserAgent("Apache-HttpClient", "org.apache.http.client", getClass()); }