Skip to content

Commit b6a5cb4

Browse files
author
Stephane Landelle
committed
Introduce useRelativeURIsWithSSLProxies, close AsyncHttpClient#236, close AsyncHttpClient#251
1 parent b9889ae commit b6a5cb4

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

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

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public class AsyncHttpClientConfig {
8484
protected HostnameVerifier hostnameVerifier;
8585
protected int ioThreadMultiplier;
8686
protected boolean strict302Handling;
87+
protected boolean useRelativeURIsWithSSLProxies;
8788

8889
protected AsyncHttpClientConfig() {
8990
}
@@ -117,7 +118,8 @@ private AsyncHttpClientConfig(int maxTotalConnections,
117118
boolean removeQueryParamOnRedirect,
118119
HostnameVerifier hostnameVerifier,
119120
int ioThreadMultiplier,
120-
boolean strict302Handling) {
121+
boolean strict302Handling,
122+
boolean useRelativeURIsWithSSLProxies) {
121123

122124
this.maxTotalConnections = maxTotalConnections;
123125
this.maxConnectionPerHost = maxConnectionPerHost;
@@ -476,6 +478,16 @@ public boolean isStrict302Handling() {
476478
return strict302Handling;
477479
}
478480

481+
/**
482+
* @return<code>true</code> if AHC should use relative URIs instead of absolute ones when talking with a SSL proxy,
483+
* otherwise <code>false</code>.
484+
*
485+
* @since 1.7.12
486+
*/
487+
public boolean isUseRelativeURIsWithSSLProxies() {
488+
return useRelativeURIsWithSSLProxies;
489+
}
490+
479491
/**
480492
* Builder for an {@link AsyncHttpClient}
481493
*/
@@ -493,6 +505,7 @@ public static class Builder {
493505
private String userAgent = System.getProperty(ASYNC_CLIENT + "userAgent", "NING/1.0");
494506
private boolean useProxyProperties = Boolean.getBoolean(ASYNC_CLIENT + "useProxyProperties");
495507
private boolean allowPoolingConnection = true;
508+
private boolean useRelativeURIsWithSSLProxies = Boolean.getBoolean(ASYNC_CLIENT + "useRelativeURIsWithSSLProxies");
496509
private ScheduledExecutorService reaper = Executors.newScheduledThreadPool(Runtime.getRuntime().availableProcessors(), new ThreadFactory() {
497510
public Thread newThread(Runnable r) {
498511
Thread t = new Thread(r, "AsyncHttpClient-Reaper");
@@ -955,6 +968,19 @@ public Builder setStrict302Handling(final boolean strict302Handling) {
955968
this.strict302Handling = strict302Handling;
956969
return this;
957970
}
971+
972+
/**
973+
* Configures this AHC instance to use relative URIs instead of absolute ones when talking with a SSL proxy.
974+
*
975+
* @param useRelativeURIsWithSSLProxies
976+
* @return this
977+
*
978+
* @since 1.7.2
979+
*/
980+
public Builder setUseRelativeURIsWithSSLProxies(boolean useRelativeURIsWithSSLProxies) {
981+
this.useRelativeURIsWithSSLProxies = useRelativeURIsWithSSLProxies;
982+
return this;
983+
}
958984

959985
/**
960986
* Create a config builder with values taken from the given prototype configuration.
@@ -1045,7 +1071,8 @@ public AsyncHttpClientConfig build() {
10451071
removeQueryParamOnRedirect,
10461072
hostnameVerifier,
10471073
ioThreadMultiplier,
1048-
strict302Handling);
1074+
strict302Handling,
1075+
useRelativeURIsWithSSLProxies);
10491076
}
10501077
}
10511078
}

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
@@ -851,6 +851,8 @@ private boolean sendAsGrizzlyRequest(final Request request,
851851
httpCtx.establishingTunnel = true;
852852
builder.method(Method.CONNECT);
853853
builder.uri(AsyncHttpProviderUtils.getAuthority(uri));
854+
} else if (secure && config.isUseRelativeURIsWithSSLProxies()){
855+
builder.uri(uri.getPath());
854856
} else {
855857
builder.uri(uri.toString());
856858
}

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
@@ -629,7 +629,7 @@ private static HttpRequest construct(AsyncHttpClientConfig config,
629629
nettyRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_0, m, AsyncHttpProviderUtils.getAuthority(uri));
630630
} else {
631631
String path = null;
632-
if (proxyServer != null)
632+
if (proxyServer != null && !isSecure(uri) && !config.isUseRelativeURIsWithSSLProxies())
633633
path = uri.toString();
634634
else if (uri.getRawQuery() != null)
635635
path = uri.getRawPath() + "?" + uri.getRawQuery();

0 commit comments

Comments
 (0)