HttpMessageEncoder should add Header "Transfer-Encoding: chunked"

if HttpMessage.isChunked(). See #171
This commit is contained in:
Norman Maurer 2012-02-02 15:24:30 +01:00
parent 1f6e96ed15
commit 6689063eef

View File

@ -25,6 +25,8 @@ import io.netty.buffer.ChannelBuffer;
import io.netty.buffer.ChannelBuffers;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.HttpHeaders.Names;
import io.netty.handler.codec.http.HttpHeaders.Values;
import io.netty.handler.codec.oneone.OneToOneEncoder;
import io.netty.util.CharsetUtil;
@ -59,7 +61,17 @@ public abstract class HttpMessageEncoder extends OneToOneEncoder {
protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
if (msg instanceof HttpMessage) {
HttpMessage m = (HttpMessage) msg;
boolean chunked = this.chunked = HttpCodecUtil.isTransferEncodingChunked(m);
boolean chunked;
if (m.isChunked()) {
// check if the Transfer-Encoding is set to chunked already.
// if not add the header to the message
if (!HttpCodecUtil.isTransferEncodingChunked(m)) {
m.addHeader(Names.TRANSFER_ENCODING, Values.CHUNKED);
}
chunked = this.chunked = true;
} else {
chunked = this.chunked = HttpCodecUtil.isTransferEncodingChunked(m);
}
ChannelBuffer header = ChannelBuffers.dynamicBuffer(
channel.getConfig().getBufferFactory());
encodeInitialLine(header, m);