[HTTPCLIENT-1952] Allow default User Agent to be disabled

This commit is contained in:
Michael Osipov 2018-12-24 00:18:11 +01:00
parent 1a8ad57a20
commit f04d81e302
1 changed files with 12 additions and 1 deletions

View File

@ -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.
* <p>
@ -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());
}