Merge pull request #241 from veebs/KeepAlive

Return "Connection: keep-alive" header in the HTTP response
This commit is contained in:
Vibul Imtarnasan 2012-03-28 22:57:18 -07:00
commit 30fabea5cd
2 changed files with 6 additions and 0 deletions

View File

@ -160,6 +160,9 @@ public class HttpStaticFileServerHandler extends SimpleChannelUpstreamHandler {
setContentLength(response, fileLength);
setContentTypeHeader(response, file);
setDateAndCacheHeaders(response, file);
if (isKeepAlive(request)) {
response.setHeader(CONNECTION, HttpHeaders.Values.KEEP_ALIVE);
}
Channel ch = e.getChannel();

View File

@ -39,6 +39,7 @@ import io.netty.handler.codec.http.CookieEncoder;
import io.netty.handler.codec.http.DefaultHttpResponse;
import io.netty.handler.codec.http.HttpChunk;
import io.netty.handler.codec.http.HttpChunkTrailer;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpResponse;
import io.netty.handler.codec.http.QueryStringDecoder;
@ -131,6 +132,8 @@ public class HttpSnoopServerHandler extends SimpleChannelUpstreamHandler {
if (keepAlive) {
// Add 'Content-Length' header only for a keep-alive connection.
response.setHeader(CONTENT_LENGTH, response.getContent().readableBytes());
// Add keep alive header as per http://www.w3.org/Protocols/HTTP/1.1/draft-ietf-http-v11-spec-01.html#Connection
response.setHeader(CONNECTION, HttpHeaders.Values.KEEP_ALIVE);
}
// Encode the cookie.