Skip to content

Commit

Permalink
assume http1.1 and use of keep-alive
Browse files Browse the repository at this point in the history
  • Loading branch information
lneves committed Mar 24, 2016
1 parent e0f5e16 commit 84048f1
Showing 1 changed file with 2 additions and 8 deletions.
Expand Up @@ -21,7 +21,6 @@
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http.HttpUtil;
import io.netty.handler.codec.http.HttpVersion;
import io.netty.util.AsciiString;
import io.netty.util.CharsetUtil;
Expand Down Expand Up @@ -101,8 +100,7 @@ public void channelRead0(ChannelHandlerContext ctx, HttpRequest msg) throws Exce
}

private void writeResponse(ChannelHandlerContext ctx, HttpRequest request, ByteBuf buf, CharSequence contentType, CharSequence contentLength) {
// Decide whether to close the connection or not.
boolean keepAlive = HttpUtil.isKeepAlive(request);

// Build the response object.
FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, buf, false);
HttpHeaders headers = response.headers();
Expand All @@ -112,11 +110,7 @@ private void writeResponse(ChannelHandlerContext ctx, HttpRequest request, ByteB
headers.set(CONTENT_LENGTH_ENTITY, contentLength);

// Close the non-keep-alive connection after the write operation is done.
if (!keepAlive) {
ctx.write(response).addListener(ChannelFutureListener.CLOSE);
} else {
ctx.write(response, ctx.voidPromise());
}
ctx.write(response, ctx.voidPromise());
}

@Override
Expand Down

0 comments on commit 84048f1

Please sign in to comment.