Skip to content

Commit

Permalink
Tweak when to mark an HTTP connection persistent
Browse files Browse the repository at this point in the history
As a server response, if no identified message length, do not persist
As a server empty body response, always assume persist
As a client request, do not assume anything
  • Loading branch information
Stephane Maldini committed Feb 26, 2018
1 parent d79643e commit 495ecf8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
11 changes: 7 additions & 4 deletions src/main/java/reactor/ipc/netty/http/HttpOperations.java
Expand Up @@ -147,10 +147,8 @@ public Mono<Void> then() {
.remove(HttpHeaderNames.TRANSFER_ENCODING);
}

if (!HttpUtil.isTransferEncodingChunked(outboundHttpMessage()) && !HttpUtil.isContentLengthSet(
outboundHttpMessage())) {
markPersistent(false);
}
shouldNotPersist();

return channel().writeAndFlush(outboundHttpMessage());
}
else {
Expand All @@ -159,6 +157,11 @@ public Mono<Void> then() {
});
}

protected void shouldNotPersist(){
//default doesn't imply anything - only server usually implies if connection
// should default persist (keep-alive) when response is not self defined
}

protected abstract HttpMessage newFullEmptyBodyMessage();

@Override
Expand Down
Expand Up @@ -281,7 +281,10 @@ public HttpHeaders responseHeaders() {
public Mono<Void> send() {
if (markSentHeaderAndBody()) {
HttpMessage response = newFullEmptyBodyMessage();
return FutureMono.deferFuture(() -> channel().writeAndFlush(response));
return FutureMono.deferFuture(() -> {
markPersistent(true);
return channel().writeAndFlush(response);
});
}
else {
return Mono.empty();
Expand Down Expand Up @@ -387,6 +390,14 @@ protected void onInboundNext(ChannelHandlerContext ctx, Object msg) {
}
}

@Override
protected void shouldNotPersist(){
if (!HttpUtil.isTransferEncodingChunked(outboundHttpMessage()) && !HttpUtil.isContentLengthSet(
outboundHttpMessage())) {
markPersistent(false);
}
}

@Override
protected void onOutboundComplete() {
if (isWebsocket()) {
Expand All @@ -402,6 +413,7 @@ protected void onOutboundComplete() {
log.debug("No sendHeaders() called before complete, sending " + "zero-length header");
}

markPersistent(true);
f = channel().writeAndFlush(newFullEmptyBodyMessage());
}
else if (markSentBody()) {
Expand Down

0 comments on commit 495ecf8

Please sign in to comment.