Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdf775c9

Browse files
committed
Ensured relative URIs are used to connect to proxied WebSockets
This needed to be done both for the Grizzly and the Netty provider.Since this is essentially the same configuration parameter as theuseRelativeURIsWithSSLProxies, I reused that parameter, but I renamed itto useRelativeURIsWithConnectProxies to reflect its true meaning sinceit's no longer used just for SSL, and I deprecated the old parameter.
1 parent2946123 commitdf775c9

File tree

5 files changed

+68
-16
lines changed

5 files changed

+68
-16
lines changed

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

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public class AsyncHttpClientConfig {
8383
protectedHostnameVerifierhostnameVerifier;
8484
protectedintioThreadMultiplier;
8585
protectedbooleanstrict302Handling;
86-
protectedbooleanuseRelativeURIsWithSSLProxies;
86+
protectedbooleanuseRelativeURIsWithConnectProxies;
8787
protectedintmaxConnectionLifeTimeInMs;
8888
protectedTimeConvertertimeConverter;
8989

@@ -120,7 +120,7 @@ private AsyncHttpClientConfig(int maxTotalConnections,
120120
HostnameVerifierhostnameVerifier,
121121
intioThreadMultiplier,
122122
booleanstrict302Handling,
123-
booleanuseRelativeURIsWithSSLProxies,
123+
booleanuseRelativeURIsWithConnectProxies,
124124
TimeConvertertimeConverter) {
125125

126126
this.maxTotalConnections =maxTotalConnections;
@@ -151,7 +151,7 @@ private AsyncHttpClientConfig(int maxTotalConnections,
151151
this.hostnameVerifier =hostnameVerifier;
152152
this.ioThreadMultiplier =ioThreadMultiplier;
153153
this.strict302Handling =strict302Handling;
154-
this.useRelativeURIsWithSSLProxies =useRelativeURIsWithSSLProxies;
154+
this.useRelativeURIsWithConnectProxies =useRelativeURIsWithConnectProxies;
155155

156156
if (applicationThreadPool ==null) {
157157
this.applicationThreadPool =Executors.newCachedThreadPool();
@@ -494,15 +494,27 @@ public boolean isStrict302Handling() {
494494
}
495495

496496
/**
497-
* @return<code>true</code> if AHC should use relative URIs instead of absolute ones when talking with a SSL proxy,
498-
* otherwise <code>false</code>.
497+
* @return<code>true</code> if AHC should use relative URIs instead of absolute ones when talking with a SSL proxy
498+
*or WebSocket proxy, otherwise <code>false</code>.
499499
*
500500
* @since 1.7.12
501+
* @deprecated Use isUseRelativeURIsWithConnectProxies instead.
501502
*/
503+
@Deprecated
502504
publicbooleanisUseRelativeURIsWithSSLProxies() {
503-
returnuseRelativeURIsWithSSLProxies;
505+
returnuseRelativeURIsWithConnectProxies;
506+
}
507+
508+
/**
509+
* @return<code>true</code> if AHC should use relative URIs instead of absolute ones when talking with a proxy
510+
* using the CONNECT method, for example when using SSL or WebSockets.
511+
*
512+
* @since 1.8.13
513+
*/
514+
publicbooleanisUseRelativeURIsWithConnectProxies() {
515+
returnuseRelativeURIsWithConnectProxies;
504516
}
505-
517+
506518
/**
507519
* 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.
508520
*
@@ -538,7 +550,7 @@ public static class Builder {
538550
privatebooleanuseProxyProperties =defaultUseProxyProperties();
539551
privatebooleanuseProxySelector =defaultUseProxySelector();
540552
privatebooleanallowPoolingConnection =defaultAllowPoolingConnection();
541-
privatebooleanuseRelativeURIsWithSSLProxies =defaultUseRelativeURIsWithSSLProxies();
553+
privatebooleanuseRelativeURIsWithConnectProxies =defaultUseRelativeURIsWithConnectProxies();
542554
privateintrequestCompressionLevel =defaultRequestCompressionLevel();
543555
privateintmaxRequestRetry =defaultMaxRequestRetry();
544556
privateintioThreadMultiplier =defaultIoThreadMultiplier();
@@ -1005,15 +1017,31 @@ public Builder setStrict302Handling(final boolean strict302Handling) {
10051017
}
10061018

10071019
/**
1008-
* Configures this AHC instance to use relative URIs instead of absolute ones when talking with a SSL proxy.
1020+
* Configures this AHC instance to use relative URIs instead of absolute ones when talking with a SSL proxy or
1021+
* WebSocket proxy.
10091022
*
10101023
* @param useRelativeURIsWithSSLProxies
10111024
* @return this
10121025
*
10131026
* @since 1.7.2
1027+
* @deprecated Use setUseRelativeURIsWithConnectProxies instead.
10141028
*/
10151029
publicBuildersetUseRelativeURIsWithSSLProxies(booleanuseRelativeURIsWithSSLProxies) {
1016-
this.useRelativeURIsWithSSLProxies =useRelativeURIsWithSSLProxies;
1030+
this.useRelativeURIsWithConnectProxies =useRelativeURIsWithSSLProxies;
1031+
returnthis;
1032+
}
1033+
1034+
/**
1035+
* Configures this AHC instance to use relative URIs instead of absolute ones when making requests through
1036+
* proxies using the CONNECT method, such as when making SSL requests or WebSocket requests.
1037+
*
1038+
* @param useRelativeURIsWithConnectProxies
1039+
* @return this
1040+
*
1041+
* @since 1.8.13
1042+
*/
1043+
publicBuildersetUseRelativeURIsWithConnectProxies(booleanuseRelativeURIsWithConnectProxies) {
1044+
this.useRelativeURIsWithConnectProxies =useRelativeURIsWithConnectProxies;
10171045
returnthis;
10181046
}
10191047

@@ -1139,7 +1167,7 @@ public Thread newThread(Runnable r) {
11391167
hostnameVerifier,
11401168
ioThreadMultiplier,
11411169
strict302Handling,
1142-
useRelativeURIsWithSSLProxies,
1170+
useRelativeURIsWithConnectProxies,
11431171
timeConverter);
11441172
}
11451173
}

‎src/main/java/com/ning/http/client/AsyncHttpClientConfigBean.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void configureDefaults() {
5858
compressionEnabled =defaultCompressionEnabled();
5959
userAgent =defaultUserAgent();
6060
allowPoolingConnection =defaultAllowPoolingConnection();
61-
useRelativeURIsWithSSLProxies =defaultUseRelativeURIsWithSSLProxies();
61+
useRelativeURIsWithConnectProxies =defaultUseRelativeURIsWithConnectProxies();
6262
requestCompressionLevel =defaultRequestCompressionLevel();
6363
maxRequestRetry =defaultMaxRequestRetry();
6464
ioThreadMultiplier =defaultIoThreadMultiplier();

‎src/main/java/com/ning/http/client/AsyncHttpClientConfigDefaults.java‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,17 @@
1313
packagecom.ning.http.client;
1414

1515
importcom.ning.http.util.AllowAllHostnameVerifier;
16+
importorg.slf4j.Logger;
17+
importorg.slf4j.LoggerFactory;
18+
1619
importstaticcom.ning.http.util.MiscUtil.getBoolean;
1720

1821
importjavax.net.ssl.HostnameVerifier;
1922

2023
publicfinalclassAsyncHttpClientConfigDefaults {
2124

25+
privatefinalstaticLoggerlog =LoggerFactory.getLogger(AsyncHttpClientConfigDefaults.class);
26+
2227
privateAsyncHttpClientConfigDefaults() {
2328
}
2429

@@ -92,8 +97,23 @@ public static boolean defaultAllowPoolingConnection() {
9297
returngetBoolean(ASYNC_CLIENT +"allowPoolingConnection",true);
9398
}
9499

100+
/**
101+
* @deprecated Use defaultUseRelativeURIsWithConnectProxies instead.
102+
*/
103+
@Deprecated
95104
publicstaticbooleandefaultUseRelativeURIsWithSSLProxies() {
96-
returngetBoolean(ASYNC_CLIENT +"useRelativeURIsWithSSLProxies",true);
105+
StringsystemPropValue =System.getProperty(ASYNC_CLIENT +"useRelativeURIsWithSSLProxies");
106+
if (systemPropValue !=null) {
107+
log.warn(ASYNC_CLIENT +"useRelativeURIsWithSSLProxies is deprecated, use " +ASYNC_CLIENT +
108+
"defaultUseRelativeURIsWithConnectProxies instead");
109+
returnsystemPropValue.equalsIgnoreCase("true");
110+
}else {
111+
returntrue;
112+
}
113+
}
114+
115+
publicstaticbooleandefaultUseRelativeURIsWithConnectProxies() {
116+
returngetBoolean(ASYNC_CLIENT +"useRelativeURIsWithConnectProxies",defaultUseRelativeURIsWithSSLProxies());
97117
}
98118

99119
// unused/broken, left there for compatibility, fixed in Netty 4

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ private boolean sendAsGrizzlyRequest(final Request request,
891891
httpCtx.establishingTunnel =true;
892892
builder.method(Method.CONNECT);
893893
builder.uri(AsyncHttpProviderUtils.getAuthority(uri));
894-
}elseif (secure &&config.isUseRelativeURIsWithSSLProxies()){
894+
}elseif ((secure||httpCtx.isWSRequest)&&config.isUseRelativeURIsWithConnectProxies()){
895895
builder.uri(uri.getPath());
896896
}else {
897897
builder.uri(uri.toString());

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -649,12 +649,16 @@ protected final static HttpRequest buildRequest(AsyncHttpClientConfig config, Re
649649
throwsIOException {
650650

651651
Stringmethod =request.getMethod();
652-
if (allowConnect &&proxyServer !=null &&(isSecure(uri) ||isWebSocket(uri.getScheme()))) {
652+
if (allowConnect &&proxyServer !=null &&useProxyConnect(uri)) {
653653
method =HttpMethod.CONNECT.toString();
654654
}
655655
returnconstruct(config,request,newHttpMethod(method),uri,buffer,proxyServer);
656656
}
657657

658+
protectedfinalstaticbooleanuseProxyConnect(URIuri) {
659+
returnisSecure(uri) ||isWebSocket(uri.getScheme());
660+
}
661+
658662
privatestaticSpnegoEnginegetSpnegoEngine() {
659663
if (spnegoEngine ==null)
660664
spnegoEngine =newSpnegoEngine();
@@ -676,7 +680,7 @@ private static HttpRequest construct(AsyncHttpClientConfig config, Request reque
676680
nettyRequest =newDefaultHttpRequest(HttpVersion.HTTP_1_0,m,AsyncHttpProviderUtils.getAuthority(uri));
677681
}else {
678682
Stringpath =null;
679-
if (proxyServer !=null && !(isSecure(uri) &&config.isUseRelativeURIsWithSSLProxies()))
683+
if (proxyServer !=null && !(useProxyConnect(uri) &&config.isUseRelativeURIsWithConnectProxies()))
680684
path =uri.toString();
681685
elseif (uri.getRawQuery() !=null)
682686
path =uri.getRawPath() +"?" +uri.getRawQuery();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp