You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2014/07/15 09:10:51 UTC
svn commit: r1610598 - in /httpcomponents/httpclient/trunk/httpclient/src:
main/java/org/apache/http/impl/client/
main/java/org/apache/http/impl/execchain/
test/java/org/apache/http/impl/execchain/
Author: olegk
Date: Tue Jul 15 07:10:50 2014
New Revision: 1610598
URL: http://svn.apache.org/r1610598
Log:
HTTPCLIENT-1526: No User-Agent set in tunneled proxy connection
Modified:
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/MainClientExec.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/execchain/TestMainClientExec.java
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java?rev=1610598&r1=1610597&r2=1610598&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java Tue Jul 15 07:10:50 2014
@@ -112,6 +112,7 @@ import org.apache.http.impl.execchain.Se
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) {
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/MainClientExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/MainClientExec.java?rev=1610598&r1=1610597&r2=1610598&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/MainClientExec.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/MainClientExec.java Tue Jul 15 07:10:50 2014
@@ -54,7 +54,6 @@ import org.apache.http.client.methods.Cl
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,12 +100,15 @@ public class MainClientExec implements C
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) {
@@ -114,22 +116,35 @@ public class MainClientExec implements C
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.proxyHttpProcessor = new ImmutableHttpProcessor(
- new RequestTargetHost(), new RequestClientConnControl());
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,
+ final HttpClientConnectionManager connManager,
+ final ConnectionReuseStrategy reuseStrategy,
+ final ConnectionKeepAliveStrategy keepAliveStrategy,
+ final AuthenticationStrategy targetAuthStrategy,
+ final AuthenticationStrategy proxyAuthStrategy,
+ final UserTokenHandler userTokenHandler) {
+ this(requestExecutor, connManager, reuseStrategy, keepAliveStrategy,
+ new ImmutableHttpProcessor(new RequestTargetHost()),
+ targetAuthStrategy, proxyAuthStrategy, userTokenHandler);
+ }
+
@Override
public CloseableHttpResponse execute(
final HttpRoute route,
Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/execchain/TestMainClientExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/execchain/TestMainClientExec.java?rev=1610598&r1=1610597&r2=1610598&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/execchain/TestMainClientExec.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/execchain/TestMainClientExec.java Tue Jul 15 07:10:50 2014
@@ -77,6 +77,7 @@ import org.apache.http.impl.conn.Connect
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);