Skip to content

Commit b25af37

Browse files
committed
Merge pull request AsyncHttpClient#29 from BluePyth/proxyfix
This pull request fixes my last one and adds a new fix.
2 parents f2d8031 + 7732db4 commit b25af37

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -492,12 +492,16 @@ public void operationComplete(ChannelFuture cf) {
492492
}
493493

494494
}
495+
496+
private static boolean isProxyServer(AsyncHttpClientConfig config, Request request) {
497+
return request.getProxyServer() != null || config.getProxyServer() != null;
498+
}
495499

496500
protected final static HttpRequest buildRequest(AsyncHttpClientConfig config, Request request, URI uri,
497501
boolean allowConnect, ChannelBuffer buffer) throws IOException {
498502

499503
String method = request.getMethod();
500-
if (allowConnect && ((request.getProxyServer() != null || config.getProxyServer() != null) && HTTPS.equalsIgnoreCase(uri.getScheme()))) {
504+
if (allowConnect && (isProxyServer(config, request) && HTTPS.equalsIgnoreCase(uri.getScheme()))) {
501505
method = HttpMethod.CONNECT.toString();
502506
}
503507
return construct(config, request, new HttpMethod(method), uri, buffer);
@@ -520,9 +524,14 @@ private static HttpRequest construct(AsyncHttpClientConfig config,
520524
if (m.equals(HttpMethod.CONNECT)) {
521525
nettyRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_0, m, AsyncHttpProviderUtils.getAuthority(uri));
522526
} else {
523-
StringBuilder path = new StringBuilder(uri.getRawPath());
524-
if (uri.getQuery() != null) {
525-
path.append("?").append(uri.getRawQuery());
527+
StringBuilder path = null;
528+
if(isProxyServer(config, request))
529+
path = new StringBuilder(uri.toString());
530+
else {
531+
path = new StringBuilder(uri.getRawPath());
532+
if (uri.getQuery() != null) {
533+
path.append("?").append(uri.getRawQuery());
534+
}
526535
}
527536
nettyRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, m, path.toString());
528537
}
@@ -631,7 +640,7 @@ private static HttpRequest construct(AsyncHttpClientConfig config,
631640
}
632641

633642
if (proxyServer.getPrincipal() != null) {
634-
if (proxyServer.getNtlmDomain() != "") {
643+
if (proxyServer.getNtlmDomain() != null && proxyServer.getNtlmDomain().length() > 0) {
635644

636645
List<String> auth = request.getHeaders().get(HttpHeaders.Names.PROXY_AUTHORIZATION);
637646
if (!(auth != null && auth.size() > 0 && auth.get(0).startsWith("NTLM"))) {

0 commit comments

Comments
 (0)