From 354ae3586ebb2557fece463c322cf2d1cc128baa Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Sun, 23 Dec 2018 20:46:25 +0100 Subject: [PATCH] [HTTPCLIENT-1952] Allow default User Agent to be disabled This closes #128 --- .../http/impl/classic/HttpClientBuilder.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpClientBuilder.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpClientBuilder.java index 7298cfcdf..983078faa 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpClientBuilder.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpClientBuilder.java @@ -229,6 +229,7 @@ public class HttpClientBuilder { private boolean cookieManagementDisabled; private boolean authCachingDisabled; private boolean connectionStateDisabled; + private boolean defaultUserAgentDisabled; private List closeables; @@ -697,6 +698,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; + } + /** * Request exec chain customization and extension. *

@@ -779,7 +790,7 @@ public class HttpClientBuilder { if (systemProperties) { userAgentCopy = System.getProperty("http.agent"); } - if (userAgentCopy == null) { + if (userAgentCopy == null && !defaultUserAgentDisabled) { userAgentCopy = VersionInfo.getSoftwareInfo("Apache-HttpClient", "org.apache.hc.client5", getClass()); }