mirror of
https://github.com/apache/httpcomponents-client.git
synced 2025-02-20 00:47:27 +00:00
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.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 @@ protected ClientExecChain createMainExec(
|
||||
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 @@ protected ClientExecChain createMainExec(
|
||||
connManager,
|
||||
reuseStrategy,
|
||||
keepAliveStrategy,
|
||||
proxyHttpProcessor,
|
||||
targetAuthStrategy,
|
||||
proxyAuthStrategy,
|
||||
userTokenHandler);
|
||||
@ -863,19 +866,6 @@ public CloseableHttpClient build() {
|
||||
userTokenHandlerCopy = NoopUserTokenHandler.INSTANCE;
|
||||
}
|
||||
}
|
||||
ClientExecChain execChain = createMainExec(
|
||||
requestExecCopy,
|
||||
connManagerCopy,
|
||||
reuseStrategyCopy,
|
||||
keepAliveStrategyCopy,
|
||||
targetAuthStrategyCopy,
|
||||
proxyAuthStrategyCopy,
|
||||
userTokenHandlerCopy);
|
||||
|
||||
execChain = decorateMainExec(execChain);
|
||||
|
||||
HttpProcessor httpprocessorCopy = this.httpprocessor;
|
||||
if (httpprocessorCopy == null) {
|
||||
|
||||
String userAgentCopy = this.userAgent;
|
||||
if (userAgentCopy == null) {
|
||||
@ -888,6 +878,21 @@ public CloseableHttpClient build() {
|
||||
}
|
||||
}
|
||||
|
||||
ClientExecChain execChain = createMainExec(
|
||||
requestExecCopy,
|
||||
connManagerCopy,
|
||||
reuseStrategyCopy,
|
||||
keepAliveStrategyCopy,
|
||||
new ImmutableHttpProcessor(new RequestTargetHost(), new RequestUserAgent(userAgentCopy)),
|
||||
targetAuthStrategyCopy,
|
||||
proxyAuthStrategyCopy,
|
||||
userTokenHandlerCopy);
|
||||
|
||||
execChain = decorateMainExec(execChain);
|
||||
|
||||
HttpProcessor httpprocessorCopy = this.httpprocessor;
|
||||
if (httpprocessorCopy == null) {
|
||||
|
||||
final HttpProcessorBuilder b = HttpProcessorBuilder.create();
|
||||
if (requestFirst != null) {
|
||||
for (final HttpRequestInterceptor i: requestFirst) {
|
||||
|
@ -54,7 +54,6 @@
|
||||
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 MainClientExec(
|
||||
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.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…
x
Reference in New Issue
Block a user