diff --git a/src/main/java/org/jboss/netty/example/http/HttpClient.java b/src/main/java/org/jboss/netty/example/http/HttpClient.java index e4991d74c7..c44453c49d 100644 --- a/src/main/java/org/jboss/netty/example/http/HttpClient.java +++ b/src/main/java/org/jboss/netty/example/http/HttpClient.java @@ -90,6 +90,7 @@ public class HttpClient { HttpRequest request = new DefaultHttpRequest( HttpVersion.HTTP_1_1, HttpMethod.GET, uri.toASCIIString()); request.addHeader(HttpHeaders.Names.HOST, host); + request.addHeader(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.CLOSE); CookieEncoder httpCookieEncoder = new CookieEncoder(false); httpCookieEncoder.addCookie("my-cookie", "foo"); httpCookieEncoder.addCookie("another-cookie", "bar"); diff --git a/src/main/java/org/jboss/netty/example/http/HttpRequestHandler.java b/src/main/java/org/jboss/netty/example/http/HttpRequestHandler.java index bb5cd04c80..07354307d2 100644 --- a/src/main/java/org/jboss/netty/example/http/HttpRequestHandler.java +++ b/src/main/java/org/jboss/netty/example/http/HttpRequestHandler.java @@ -131,7 +131,12 @@ public class HttpRequestHandler extends SimpleChannelUpstreamHandler { HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK); response.setContent(buf); response.setHeader(HttpHeaders.Names.CONTENT_TYPE, "text/plain; charset=UTF-8"); - response.setHeader(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(buf.readableBytes())); + + if (!close) { + // There's no need to add 'Content-Length' header + // if this is the last response. + response.setHeader(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(buf.readableBytes())); + } String cookieString = request.getHeader(HttpHeaders.Names.COOKIE); if (cookieString != null) {