Skip to content

Commit 29b97a2

Browse files
committed
Drop markUnderlyingConnectionAsToBeClosed , close connection when AsyncHandler.onBodyPartReceived doesn't say to continue, close AsyncHttpClient#982
1 parent f865fc0 commit 29b97a2

File tree

5 files changed

+3
-36
lines changed

5 files changed

+3
-36
lines changed

client/src/main/java/org/asynchttpclient/AsyncHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ enum State {
7474
* Beware that, depending on the provider (Netty) this can be notified with empty body parts.
7575
*
7676
* @param bodyPart response's body part.
77-
* @return a {@link State} telling to CONTINUE or ABORT the current processing.
77+
* @return a {@link State} telling to CONTINUE or ABORT the current processing. Aborting will also close the connection.
7878
* @throws Exception if something wrong happens
7979
*/
8080
State onBodyPartReceived(HttpResponseBodyPart bodyPart) throws Exception;

client/src/main/java/org/asynchttpclient/HttpResponseBodyPart.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,4 @@ public interface HttpResponseBodyPart {
4242
* @return true if this is the last part.
4343
*/
4444
boolean isLast();
45-
46-
/**
47-
* Close the underlying connection once the processing has completed. Invoking that method means the
48-
* underlying TCP connection will be closed as soon as the processing of the response is completed. That
49-
* means the underlying connection will never get pooled.
50-
*/
51-
void markUnderlyingConnectionAsToBeClosed();
52-
53-
/**
54-
* @return true of the underlying connection will be closed once the response has been fully processed.
55-
*/
56-
boolean isUnderlyingConnectionToBeClosed();
5745
}

client/src/main/java/org/asynchttpclient/netty/NettyResponseBodyPart.java

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
public abstract class NettyResponseBodyPart implements HttpResponseBodyPart {
2222

2323
private final boolean last;
24-
private boolean closeConnection;
2524

2625
public NettyResponseBodyPart(boolean last) {
2726
this.last = last;
@@ -34,20 +33,4 @@ public NettyResponseBodyPart(boolean last) {
3433
public boolean isLast() {
3534
return last;
3635
}
37-
38-
/**
39-
* {@inheritDoc}
40-
*/
41-
@Override
42-
public void markUnderlyingConnectionAsToBeClosed() {
43-
closeConnection = true;
44-
}
45-
46-
/**
47-
* {@inheritDoc}
48-
*/
49-
@Override
50-
public boolean isUnderlyingConnectionToBeClosed() {
51-
return closeConnection;
52-
}
5336
}

client/src/main/java/org/asynchttpclient/netty/handler/HttpProtocol.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ private void finishUpdate(final NettyResponseFuture<?> future, Channel channel,
151151

152152
private boolean updateBodyAndInterrupt(NettyResponseFuture<?> future, AsyncHandler<?> handler, NettyResponseBodyPart bodyPart) throws Exception {
153153
boolean interrupt = handler.onBodyPartReceived(bodyPart) != State.CONTINUE;
154-
if (bodyPart.isUnderlyingConnectionToBeClosed())
154+
if (interrupt)
155155
future.setKeepAlive(false);
156156
return interrupt;
157157
}

client/src/test/java/org/asynchttpclient/AsyncStreamHandlerTest.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -447,11 +447,7 @@ public void onThrowable(Throwable t) {
447447

448448
public State onBodyPartReceived(HttpResponseBodyPart content) throws Exception {
449449
builder.accumulate(content);
450-
451-
if (content.isLast()) {
452-
content.markUnderlyingConnectionAsToBeClosed();
453-
}
454-
return State.CONTINUE;
450+
return content.isLast() ? State.ABORT : State.CONTINUE;
455451
}
456452

457453
public State onStatusReceived(HttpResponseStatus responseStatus) throws Exception {

0 commit comments

Comments
 (0)