Skip to content

Commit a1b8674

Browse files
author
Stephane Landelle
committed
Remove useless calls to Request.getUrl, close AsyncHttpClient#582
1 parent 914453d commit a1b8674

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,9 @@ private <T> ListenableFuture<T> doConnect(final Request request, final AsyncHand
986986
throw new IOException("Closed");
987987
}
988988

989-
if (request.getUrl().startsWith(WEBSOCKET) && !validateWebSocketRequest(request, asyncHandler)) {
989+
URI uri = useRawUrl ? request.getRawURI() : request.getURI();
990+
991+
if (uri.getScheme().startsWith(WEBSOCKET) && !validateWebSocketRequest(request, asyncHandler)) {
990992
throw new IOException("WebSocket method must be a GET");
991993
}
992994

@@ -995,8 +997,6 @@ private <T> ListenableFuture<T> doConnect(final Request request, final AsyncHand
995997
boolean resultOfAConnect = f != null && f.getNettyRequest() != null && f.getNettyRequest().getMethod().equals(HttpMethod.CONNECT);
996998
boolean useProxy = proxyServer != null && !resultOfAConnect;
997999

998-
URI uri = useRawUrl ? request.getRawURI() : request.getURI();
999-
10001000
ChannelBuffer bufferedBytes = null;
10011001
if (f != null && f.getRequest().getFile() == null && !f.getNettyRequest().getMethod().getName().equals(HttpMethod.CONNECT.getName())) {
10021002
bufferedBytes = f.getNettyRequest().getContent();
@@ -1069,7 +1069,7 @@ private <T> ListenableFuture<T> doConnect(final Request request, final AsyncHand
10691069
}
10701070

10711071
ChannelFuture channelFuture;
1072-
ClientBootstrap bootstrap = (request.getUrl().startsWith(WEBSOCKET) && !useProxy) ? (useSSl ? secureWebSocketBootstrap : webSocketBootstrap) : (useSSl ? secureBootstrap
1072+
ClientBootstrap bootstrap = (request.getURI().getScheme().startsWith(WEBSOCKET) && !useProxy) ? (useSSl ? secureWebSocketBootstrap : webSocketBootstrap) : (useSSl ? secureBootstrap
10731073
: plainBootstrap);
10741074
bootstrap.setOption("connectTimeoutMillis", config.getConnectionTimeoutInMs());
10751075

@@ -1977,7 +1977,7 @@ private boolean redirect(Request request, NettyResponseFuture<?> future, HttpRes
19771977
final String initialPoolKey = getPoolKey(future);
19781978
future.setURI(uri);
19791979
String newUrl = uri.toString();
1980-
if (request.getUrl().startsWith(WEBSOCKET)) {
1980+
if (request.getURI().getScheme().startsWith(WEBSOCKET)) {
19811981
newUrl = newUrl.replace(HTTP, WEBSOCKET);
19821982
}
19831983

@@ -2128,7 +2128,7 @@ public void handle(final ChannelHandlerContext ctx, final MessageEvent e) throws
21282128
String realmURI = computeRealmURI(newRealm, request.getURI());
21292129
final Realm nr = new Realm.RealmBuilder().clone(newRealm).setUri(realmURI).build();
21302130

2131-
log.debug("Sending authentication to {}", request.getUrl());
2131+
log.debug("Sending authentication to {}", request.getURI());
21322132
AsyncCallable ac = new AsyncCallable(future) {
21332133
public Object call() throws Exception {
21342134
drainChannel(ctx, future);
@@ -2156,7 +2156,7 @@ public Object call() throws Exception {
21562156
List<String> proxyAuth = getAuthorizationToken(response.getHeaders(), HttpHeaders.Names.PROXY_AUTHENTICATE);
21572157
if (statusCode == 407 && realm != null && !proxyAuth.isEmpty() && !future.getAndSetAuth(true)) {
21582158

2159-
log.debug("Sending proxy authentication to {}", request.getUrl());
2159+
log.debug("Sending proxy authentication to {}", request.getURI());
21602160

21612161
future.setState(NettyResponseFuture.STATE.NEW);
21622162
Realm newRealm = null;
@@ -2188,8 +2188,9 @@ public Object call() throws Exception {
21882188
}
21892189

21902190
try {
2191-
log.debug("Connecting to proxy {} for scheme {}", proxyServer, request.getUrl());
2192-
upgradeProtocol(ctx.getChannel().getPipeline(), request.getURI().getScheme());
2191+
String scheme = request.getURI().getScheme();
2192+
log.debug("Connecting to proxy {} for scheme {}", proxyServer, scheme);
2193+
upgradeProtocol(ctx.getChannel().getPipeline(), scheme);
21932194
} catch (Throwable ex) {
21942195
abort(future, ex);
21952196
}

0 commit comments

Comments
 (0)