From 912c66b9310bc44c900aadbe907e1813524f9cf9 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Thu, 12 Feb 2009 07:01:26 +0000 Subject: [PATCH] Forgot to encode the last chunk correctly --- .../codec/http/HttpMessageEncoder.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/jboss/netty/handler/codec/http/HttpMessageEncoder.java b/src/main/java/org/jboss/netty/handler/codec/http/HttpMessageEncoder.java index a4de9371e3..9dbc7c9161 100644 --- a/src/main/java/org/jboss/netty/handler/codec/http/HttpMessageEncoder.java +++ b/src/main/java/org/jboss/netty/handler/codec/http/HttpMessageEncoder.java @@ -45,6 +45,8 @@ import org.jboss.netty.handler.codec.oneone.OneToOneEncoder; @ChannelPipelineCoverage("one") public abstract class HttpMessageEncoder extends OneToOneEncoder { + private static final ChannelBuffer LAST_CHUNK = copiedBuffer("0\r\n\r\n", "USASCII"); + @Override protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { if (msg instanceof HttpMessage) { @@ -65,14 +67,18 @@ public abstract class HttpMessageEncoder extends OneToOneEncoder { if (msg instanceof HttpChunk) { HttpChunk chunk = (HttpChunk) msg; - ChannelBuffer content = chunk.getContent(); - int contentLength = content.readableBytes(); + if (chunk.isLast()) { + return LAST_CHUNK.duplicate(); + } else { + ChannelBuffer content = chunk.getContent(); + int contentLength = content.readableBytes(); - return wrappedBuffer( - copiedBuffer(Integer.toHexString(contentLength), "USASCII"), - wrappedBuffer(CRLF), - content.slice(content.readerIndex(), contentLength), - wrappedBuffer(CRLF)); + return wrappedBuffer( + copiedBuffer(Integer.toHexString(contentLength), "USASCII"), + wrappedBuffer(CRLF), + content.slice(content.readerIndex(), contentLength), + wrappedBuffer(CRLF)); + } } // Unknown message type.