HTTPCLIENT-1402: Cache default User-Agent value
Contributed by yuexiaojun <junedo at qq.com> git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1525568 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
613ef11aaf
commit
eeee0720b5
|
@ -1,6 +1,9 @@
|
|||
Changes since 4.3
|
||||
-------------------
|
||||
|
||||
* [HTTPCLIENT-1402] Cache default User-Agent value.
|
||||
Contributed by yuexiaojun <junedo at qq.com>
|
||||
|
||||
* [HTTPCLIENT-1398] Fixed invalid OSGi metadata caused by corrupted Maven bundle plugin metadata.
|
||||
Contributed by Oleg Kalnichevski <olegk at apache.org>
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -198,6 +198,15 @@ public class HttpClientBuilder {
|
|||
|
||||
private List<Closeable> 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue