Skip to content

Commit be05829

Browse files
author
Stephane Landelle
committed
Introduce useRelativeURIsWithSSLProxies, close #236, close #251
1 parent 6866b1d commit be05829

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

api/src/main/java/com/ning/http/client/AsyncHttpClientConfig.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ public class AsyncHttpClientConfig {
109109
protected int ioThreadMultiplier;
110110
protected boolean strict302Handling;
111111
protected int maxConnectionLifeTimeInMs;
112+
protected boolean useRelativeURIsWithSSLProxies;
112113

113114
protected AsyncHttpClientConfig() {
114115
}
@@ -143,7 +144,8 @@ private AsyncHttpClientConfig(int maxTotalConnections,
143144
boolean removeQueryParamOnRedirect,
144145
HostnameVerifier hostnameVerifier,
145146
int ioThreadMultiplier,
146-
boolean strict302Handling) {
147+
boolean strict302Handling,
148+
boolean useRelativeURIsWithSSLProxies) {
147149

148150
this.maxTotalConnections = maxTotalConnections;
149151
this.maxConnectionPerHost = maxConnectionPerHost;
@@ -174,6 +176,7 @@ private AsyncHttpClientConfig(int maxTotalConnections,
174176
this.hostnameVerifier = hostnameVerifier;
175177
this.ioThreadMultiplier = ioThreadMultiplier;
176178
this.strict302Handling = strict302Handling;
179+
this.useRelativeURIsWithSSLProxies = useRelativeURIsWithSSLProxies;
177180

178181
if (applicationThreadPool == null) {
179182
this.applicationThreadPool = Executors.newCachedThreadPool();
@@ -503,6 +506,16 @@ public boolean isStrict302Handling() {
503506
return strict302Handling;
504507
}
505508

509+
/**
510+
* @return<code>true</code> if AHC should use relative URIs instead of absolute ones when talking with a SSL proxy,
511+
* otherwise <code>false</code>.
512+
*
513+
* @since 1.7.12
514+
*/
515+
public boolean isUseRelativeURIsWithSSLProxies() {
516+
return useRelativeURIsWithSSLProxies;
517+
}
518+
506519
/**
507520
* Return the maximum time in millisecond an {@link com.ning.http.client.AsyncHttpClient} will keep connection in the pool, or -1 to keep connection while possible.
508521
*
@@ -530,6 +543,7 @@ public static class Builder {
530543
private String userAgent = System.getProperty(ASYNC_CLIENT + "userAgent", "AsyncHttpClient/" + AHC_VERSION);
531544
private boolean useProxyProperties = Boolean.getBoolean(ASYNC_CLIENT + "useProxyProperties");
532545
private boolean allowPoolingConnection = true;
546+
private boolean useRelativeURIsWithSSLProxies = Boolean.getBoolean(ASYNC_CLIENT + "useRelativeURIsWithSSLProxies");
533547
private ScheduledExecutorService reaper = Executors.newScheduledThreadPool(Runtime.getRuntime().availableProcessors(), new ThreadFactory() {
534548
public Thread newThread(Runnable r) {
535549
Thread t = new Thread(r, "AsyncHttpClient-Reaper");
@@ -1004,6 +1018,19 @@ public Builder setMaxConnectionLifeTimeInMs(int maxConnectionLifeTimeInMs) {
10041018
return this;
10051019
}
10061020

1021+
/**
1022+
* Configures this AHC instance to use relative URIs instead of absolute ones when talking with a SSL proxy.
1023+
*
1024+
* @param useRelativeURIsWithSSLProxies
1025+
* @return this
1026+
*
1027+
* @since 1.7.2
1028+
*/
1029+
public Builder setUseRelativeURIsWithSSLProxies(boolean useRelativeURIsWithSSLProxies) {
1030+
this.useRelativeURIsWithSSLProxies = useRelativeURIsWithSSLProxies;
1031+
return this;
1032+
}
1033+
10071034
/**
10081035
* Create a config builder with values taken from the given prototype configuration.
10091036
*
@@ -1047,6 +1074,7 @@ public Builder(AsyncHttpClientConfig prototype) {
10471074
removeQueryParamOnRedirect = prototype.isRemoveQueryParamOnRedirect();
10481075
hostnameVerifier = prototype.getHostnameVerifier();
10491076
strict302Handling = prototype.isStrict302Handling();
1077+
useRelativeURIsWithSSLProxies = prototype.isUseRelativeURIsWithSSLProxies();
10501078
}
10511079

10521080
/**
@@ -1095,7 +1123,8 @@ public AsyncHttpClientConfig build() {
10951123
removeQueryParamOnRedirect,
10961124
hostnameVerifier,
10971125
ioThreadMultiplier,
1098-
strict302Handling);
1126+
strict302Handling,
1127+
useRelativeURIsWithSSLProxies);
10991128
}
11001129
}
11011130
}

providers/grizzly/src/main/java/com/ning/http/client/providers/grizzly/GrizzlyAsyncHttpProvider.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,8 @@ private boolean sendAsGrizzlyRequest(final Request request,
871871
httpCtx.establishingTunnel = true;
872872
builder.method(Method.CONNECT);
873873
builder.uri(AsyncHttpProviderUtils.getAuthority(uri));
874+
} else if (secure && config.isUseRelativeURIsWithSSLProxies()){
875+
builder.uri(uri.getPath());
874876
} else {
875877
builder.uri(uri.toString());
876878
}

providers/netty/src/main/java/com/ning/http/client/providers/netty/NettyAsyncHttpProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ private static HttpRequest construct(AsyncHttpClientConfig config,
594594
nettyRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_0, m, AsyncHttpProviderUtils.getAuthority(uri));
595595
} else {
596596
String path = null;
597-
if (proxyServer != null)
597+
if (proxyServer != null && !(isSecure(uri) && config.isUseRelativeURIsWithSSLProxies()))
598598
path = uri.toString();
599599
else if (uri.getRawQuery() != null)
600600
path = uri.getRawPath() + "?" + uri.getRawQuery();

0 commit comments

Comments
 (0)