HTTPCLIENT-1526: No User-Agent set in tunneled proxy connection
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1610598 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7284afbe71
commit
d7c64ee9c0
|
@ -112,6 +112,7 @@ import org.apache.http.impl.execchain.ServiceUnavailableRetryExec;
|
|||
import org.apache.http.protocol.HttpProcessor;
|
||||
import org.apache.http.protocol.HttpProcessorBuilder;
|
||||
import org.apache.http.protocol.HttpRequestExecutor;
|
||||
import org.apache.http.protocol.ImmutableHttpProcessor;
|
||||
import org.apache.http.protocol.RequestContent;
|
||||
import org.apache.http.protocol.RequestTargetHost;
|
||||
import org.apache.http.protocol.RequestUserAgent;
|
||||
|
@ -714,6 +715,7 @@ public class HttpClientBuilder {
|
|||
final HttpClientConnectionManager connManager,
|
||||
final ConnectionReuseStrategy reuseStrategy,
|
||||
final ConnectionKeepAliveStrategy keepAliveStrategy,
|
||||
final HttpProcessor proxyHttpProcessor,
|
||||
final AuthenticationStrategy targetAuthStrategy,
|
||||
final AuthenticationStrategy proxyAuthStrategy,
|
||||
final UserTokenHandler userTokenHandler)
|
||||
|
@ -723,6 +725,7 @@ public class HttpClientBuilder {
|
|||
connManager,
|
||||
reuseStrategy,
|
||||
keepAliveStrategy,
|
||||
proxyHttpProcessor,
|
||||
targetAuthStrategy,
|
||||
proxyAuthStrategy,
|
||||
userTokenHandler);
|
||||
|
@ -863,11 +866,24 @@ public class HttpClientBuilder {
|
|||
userTokenHandlerCopy = NoopUserTokenHandler.INSTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
String userAgentCopy = this.userAgent;
|
||||
if (userAgentCopy == null) {
|
||||
if (systemProperties) {
|
||||
userAgentCopy = System.getProperty("http.agent");
|
||||
}
|
||||
if (userAgentCopy == null) {
|
||||
userAgentCopy = VersionInfo.getUserAgent("Apache-HttpClient",
|
||||
"org.apache.http.client", getClass());
|
||||
}
|
||||
}
|
||||
|
||||
ClientExecChain execChain = createMainExec(
|
||||
requestExecCopy,
|
||||
connManagerCopy,
|
||||
reuseStrategyCopy,
|
||||
keepAliveStrategyCopy,
|
||||
new ImmutableHttpProcessor(new RequestTargetHost(), new RequestUserAgent(userAgentCopy)),
|
||||
targetAuthStrategyCopy,
|
||||
proxyAuthStrategyCopy,
|
||||
userTokenHandlerCopy);
|
||||
|
@ -877,17 +893,6 @@ public class HttpClientBuilder {
|
|||
HttpProcessor httpprocessorCopy = this.httpprocessor;
|
||||
if (httpprocessorCopy == null) {
|
||||
|
||||
String userAgentCopy = this.userAgent;
|
||||
if (userAgentCopy == null) {
|
||||
if (systemProperties) {
|
||||
userAgentCopy = System.getProperty("http.agent");
|
||||
}
|
||||
if (userAgentCopy == null) {
|
||||
userAgentCopy = VersionInfo.getUserAgent("Apache-HttpClient",
|
||||
"org.apache.http.client", getClass());
|
||||
}
|
||||
}
|
||||
|
||||
final HttpProcessorBuilder b = HttpProcessorBuilder.create();
|
||||
if (requestFirst != null) {
|
||||
for (final HttpRequestInterceptor i: requestFirst) {
|
||||
|
|
|
@ -54,7 +54,6 @@ import org.apache.http.client.methods.CloseableHttpResponse;
|
|||
import org.apache.http.client.methods.HttpExecutionAware;
|
||||
import org.apache.http.client.methods.HttpRequestWrapper;
|
||||
import org.apache.http.client.protocol.HttpClientContext;
|
||||
import org.apache.http.client.protocol.RequestClientConnControl;
|
||||
import org.apache.http.conn.ConnectionKeepAliveStrategy;
|
||||
import org.apache.http.conn.ConnectionRequest;
|
||||
import org.apache.http.conn.HttpClientConnectionManager;
|
||||
|
@ -101,6 +100,37 @@ public class MainClientExec implements ClientExecChain {
|
|||
private final UserTokenHandler userTokenHandler;
|
||||
private final HttpRouteDirector routeDirector;
|
||||
|
||||
/**
|
||||
* @since 4.4
|
||||
*/
|
||||
public MainClientExec(
|
||||
final HttpRequestExecutor requestExecutor,
|
||||
final HttpClientConnectionManager connManager,
|
||||
final ConnectionReuseStrategy reuseStrategy,
|
||||
final ConnectionKeepAliveStrategy keepAliveStrategy,
|
||||
final HttpProcessor proxyHttpProcessor,
|
||||
final AuthenticationStrategy targetAuthStrategy,
|
||||
final AuthenticationStrategy proxyAuthStrategy,
|
||||
final UserTokenHandler userTokenHandler) {
|
||||
Args.notNull(requestExecutor, "HTTP request executor");
|
||||
Args.notNull(connManager, "Client connection manager");
|
||||
Args.notNull(reuseStrategy, "Connection reuse strategy");
|
||||
Args.notNull(keepAliveStrategy, "Connection keep alive strategy");
|
||||
Args.notNull(proxyHttpProcessor, "Proxy HTTP processor");
|
||||
Args.notNull(targetAuthStrategy, "Target authentication strategy");
|
||||
Args.notNull(proxyAuthStrategy, "Proxy authentication strategy");
|
||||
Args.notNull(userTokenHandler, "User token handler");
|
||||
this.authenticator = new HttpAuthenticator();
|
||||
this.routeDirector = new BasicRouteDirector();
|
||||
this.requestExecutor = requestExecutor;
|
||||
this.connManager = connManager;
|
||||
this.reuseStrategy = reuseStrategy;
|
||||
this.keepAliveStrategy = keepAliveStrategy;
|
||||
this.proxyHttpProcessor = proxyHttpProcessor;
|
||||
this.targetAuthStrategy = targetAuthStrategy;
|
||||
this.proxyAuthStrategy = proxyAuthStrategy;
|
||||
this.userTokenHandler = userTokenHandler;
|
||||
}
|
||||
|
||||
public MainClientExec(
|
||||
final HttpRequestExecutor requestExecutor,
|
||||
|
@ -110,24 +140,9 @@ public class MainClientExec implements ClientExecChain {
|
|||
final AuthenticationStrategy targetAuthStrategy,
|
||||
final AuthenticationStrategy proxyAuthStrategy,
|
||||
final UserTokenHandler userTokenHandler) {
|
||||
Args.notNull(requestExecutor, "HTTP request executor");
|
||||
Args.notNull(connManager, "Client connection manager");
|
||||
Args.notNull(reuseStrategy, "Connection reuse strategy");
|
||||
Args.notNull(keepAliveStrategy, "Connection keep alive strategy");
|
||||
Args.notNull(targetAuthStrategy, "Target authentication strategy");
|
||||
Args.notNull(proxyAuthStrategy, "Proxy authentication strategy");
|
||||
Args.notNull(userTokenHandler, "User token handler");
|
||||
this.authenticator = new HttpAuthenticator();
|
||||
this.proxyHttpProcessor = new ImmutableHttpProcessor(
|
||||
new RequestTargetHost(), new RequestClientConnControl());
|
||||
this.routeDirector = new BasicRouteDirector();
|
||||
this.requestExecutor = requestExecutor;
|
||||
this.connManager = connManager;
|
||||
this.reuseStrategy = reuseStrategy;
|
||||
this.keepAliveStrategy = keepAliveStrategy;
|
||||
this.targetAuthStrategy = targetAuthStrategy;
|
||||
this.proxyAuthStrategy = proxyAuthStrategy;
|
||||
this.userTokenHandler = userTokenHandler;
|
||||
this(requestExecutor, connManager, reuseStrategy, keepAliveStrategy,
|
||||
new ImmutableHttpProcessor(new RequestTargetHost()),
|
||||
targetAuthStrategy, proxyAuthStrategy, userTokenHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -77,6 +77,7 @@ import org.apache.http.impl.conn.ConnectionShutdownException;
|
|||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.message.BasicHttpResponse;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
import org.apache.http.protocol.HttpProcessor;
|
||||
import org.apache.http.protocol.HttpRequestExecutor;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.junit.Assert;
|
||||
|
@ -101,6 +102,8 @@ public class TestMainClientExec {
|
|||
@Mock
|
||||
private ConnectionKeepAliveStrategy keepAliveStrategy;
|
||||
@Mock
|
||||
private HttpProcessor proxyHttpProcessor;
|
||||
@Mock
|
||||
private AuthenticationStrategy targetAuthStrategy;
|
||||
@Mock
|
||||
private AuthenticationStrategy proxyAuthStrategy;
|
||||
|
@ -121,7 +124,7 @@ public class TestMainClientExec {
|
|||
public void setup() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mainClientExec = new MainClientExec(requestExecutor, connManager, reuseStrategy,
|
||||
keepAliveStrategy, targetAuthStrategy, proxyAuthStrategy, userTokenHandler);
|
||||
keepAliveStrategy, proxyHttpProcessor, targetAuthStrategy, proxyAuthStrategy, userTokenHandler);
|
||||
target = new HttpHost("foo", 80);
|
||||
proxy = new HttpHost("bar", 8888);
|
||||
|
||||
|
|
Loading…
Reference in New Issue