Skip to content

Commit e3d5db5

Browse files
author
Stephane Landelle
committed
Don't pass nettyRequest to writeRequest: it's in the future
1 parent d670f59 commit e3d5db5

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,10 @@ private Channel verifyChannelPipeline(Channel channel, String scheme) throws IOE
435435
return channel;
436436
}
437437

438-
protected final <T> void writeRequest(final Channel channel, final AsyncHttpClientConfig config, final NettyResponseFuture<T> future, final HttpRequest nettyRequest) {
438+
protected final <T> void writeRequest(final Channel channel, final AsyncHttpClientConfig config, final NettyResponseFuture<T> future) {
439+
440+
HttpRequest nettyRequest = future.getNettyRequest();
441+
439442
try {
440443
/**
441444
* If the channel is dead because it was pooled and the remote server decided to close it, we just let it go and the closeChannel do it's work.
@@ -445,7 +448,7 @@ protected final <T> void writeRequest(final Channel channel, final AsyncHttpClie
445448
}
446449

447450
Body body = null;
448-
if (!future.getNettyRequest().getMethod().equals(HttpMethod.CONNECT)) {
451+
if (!nettyRequest.getMethod().equals(HttpMethod.CONNECT)) {
449452
BodyGenerator bg = future.getRequest().getBodyGenerator();
450453
if (bg != null) {
451454
// Netty issue with chunking.
@@ -472,8 +475,8 @@ protected final <T> void writeRequest(final Channel channel, final AsyncHttpClie
472475
if (future.getAsyncHandler() instanceof TransferCompletionHandler) {
473476

474477
FluentCaseInsensitiveStringsMap h = new FluentCaseInsensitiveStringsMap();
475-
for (String s : future.getNettyRequest().getHeaderNames()) {
476-
for (String header : future.getNettyRequest().getHeaders(s)) {
478+
for (String s : nettyRequest.getHeaderNames()) {
479+
for (String header : nettyRequest.getHeaders(s)) {
477480
h.add(s, header);
478481
}
479482
}
@@ -497,7 +500,7 @@ protected final <T> void writeRequest(final Channel channel, final AsyncHttpClie
497500
}
498501

499502
if (future.getAndSetWriteBody(true)) {
500-
if (!future.getNettyRequest().getMethod().equals(HttpMethod.CONNECT)) {
503+
if (!nettyRequest.getMethod().equals(HttpMethod.CONNECT)) {
501504

502505
if (future.getRequest().getFile() != null) {
503506
final File file = future.getRequest().getFile();
@@ -538,8 +541,8 @@ public void operationComplete(ChannelFuture cf) {
538541
* TODO: AHC-78: SSL + zero copy isn't supported by the MultiPart class and pretty complex to implements.
539542
*/
540543
if (future.getRequest().getParts() != null) {
541-
String contentType = future.getNettyRequest().getHeader(HttpHeaders.Names.CONTENT_TYPE);
542-
String length = future.getNettyRequest().getHeader(HttpHeaders.Names.CONTENT_LENGTH);
544+
String contentType = nettyRequest.getHeader(HttpHeaders.Names.CONTENT_TYPE);
545+
String length = nettyRequest.getHeader(HttpHeaders.Names.CONTENT_LENGTH);
543546
body = new MultipartBody(future.getRequest().getParts(), contentType, length);
544547
}
545548

@@ -953,7 +956,7 @@ private <T> ListenableFuture<T> doConnect(final Request request, final AsyncHand
953956
channel.getPipeline().getContext(NettyAsyncHttpProvider.class).setAttachment(f);
954957

955958
try {
956-
writeRequest(channel, config, f, nettyRequest);
959+
writeRequest(channel, config, f);
957960
} catch (Exception ex) {
958961
log.debug("writeRequest failure", ex);
959962
if (useSSl && ex.getMessage() != null && ex.getMessage().contains("SSLEngine")) {
@@ -2144,7 +2147,7 @@ public Object call() throws Exception {
21442147
if (statusCode == 100) {
21452148
future.getAndSetWriteHeaders(false);
21462149
future.getAndSetWriteBody(true);
2147-
writeRequest(ctx.getChannel(), config, future, nettyRequest);
2150+
writeRequest(ctx.getChannel(), config, future);
21482151
return;
21492152
}
21502153

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,10 @@ final class NettyConnectListener<T> implements ChannelFutureListener {
5252
private final AtomicBoolean handshakeDone = new AtomicBoolean(false);
5353

5454
private NettyConnectListener(AsyncHttpClientConfig config,
55-
NettyResponseFuture<T> future,
56-
HttpRequest nettyRequest) {
55+
NettyResponseFuture<T> future) {
5756
this.config = config;
5857
this.future = future;
59-
this.nettyRequest = nettyRequest;
58+
this.nettyRequest = future.getNettyRequest();
6059
}
6160

6261
public NettyResponseFuture<T> future() {
@@ -82,7 +81,7 @@ public final void operationComplete(ChannelFuture f) throws Exception {
8281
}
8382
}
8483

85-
future.provider().writeRequest(f.getChannel(), config, future, nettyRequest);
84+
future.provider().writeRequest(f.getChannel(), config, future);
8685
} else {
8786
Throwable cause = f.getCause();
8887

@@ -148,7 +147,7 @@ public NettyConnectListener<T> build(final URI uri) throws IOException {
148147
future.setNettyRequest(nettyRequest);
149148
future.setRequest(request);
150149
}
151-
return new NettyConnectListener<T>(config, future, nettyRequest);
150+
return new NettyConnectListener<T>(config, future);
152151
}
153152
}
154153
}

0 commit comments

Comments
 (0)