* Use HttpRequest.isKeepAlive() instead of long conditionals

* Use HttpChunkAggregator because we don't want to complicate the example
This commit is contained in:
Trustin Lee 2010-01-08 08:33:48 +00:00
parent f926c0adc0
commit 9f8fa65a14
2 changed files with 3 additions and 10 deletions

View File

@ -56,11 +56,6 @@ public class HttpStaticFileServerHandler extends SimpleChannelUpstreamHandler {
return;
}
if (request.isChunked()) {
sendError(ctx, HttpResponseStatus.BAD_REQUEST);
return;
}
String path = sanitizeUri(request.getUri());
if (path == null) {
sendError(ctx, HttpResponseStatus.FORBIDDEN);
@ -100,11 +95,7 @@ public class HttpStaticFileServerHandler extends SimpleChannelUpstreamHandler {
ChannelFuture writeFuture = ch.write(new ChunkedFile(raf, 0, fileLength, 8192));
// Decide whether to close the connection or not.
boolean close =
HttpHeaders.Values.CLOSE.equalsIgnoreCase(request.getHeader(HttpHeaders.Names.CONNECTION)) ||
request.getProtocolVersion().equals(HttpVersion.HTTP_1_0) &&
!HttpHeaders.Values.KEEP_ALIVE.equalsIgnoreCase(request.getHeader(HttpHeaders.Names.CONNECTION));
boolean close = !request.isKeepAlive();
if (close) {
// Close the connection when the whole content is written out.
writeFuture.addListener(ChannelFutureListener.CLOSE);

View File

@ -19,6 +19,7 @@ import static org.jboss.netty.channel.Channels.*;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.handler.codec.http.HttpChunkAggregator;
import org.jboss.netty.handler.codec.http.HttpRequestDecoder;
import org.jboss.netty.handler.codec.http.HttpResponseEncoder;
import org.jboss.netty.handler.stream.ChunkedWriteHandler;
@ -38,6 +39,7 @@ public class HttpStaticFileServerPipelineFactory implements ChannelPipelineFacto
//pipeline.addLast("ssl", new SslHandler(engine));
pipeline.addLast("decoder", new HttpRequestDecoder());
pipeline.addLast("aggregator", new HttpChunkAggregator(65536));
pipeline.addLast("encoder", new HttpResponseEncoder());
pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());