Skip to content

Commit

Permalink
[netty#1595] Fix IllegalStateException thrown by HttpObjectEncoder wh…
Browse files Browse the repository at this point in the history
…en an empty HttpContent was written
  • Loading branch information
Norman Maurer committed Jul 17, 2013
1 parent b9bae2b commit 66c4c07
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.netty.handler.codec.http;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageEncoder;
import io.netty.util.CharsetUtil;
Expand Down Expand Up @@ -81,6 +82,10 @@ protected void encode(ChannelHandlerContext ctx, HttpObject msg, List<Object> ou
if (state == ST_CONTENT_NON_CHUNK) {
if (contentLength > 0) {
out.add(content.retain());
} else {
// Need to produce some output otherwise an
// IllegalstateException will be thrown
out.add(Unpooled.EMPTY_BUFFER);
}

if (chunk instanceof LastHttpContent) {
Expand Down Expand Up @@ -110,6 +115,12 @@ protected void encode(ChannelHandlerContext ctx, HttpObject msg, List<Object> ou
}

state = ST_INIT;
} else {
if (contentLength == 0) {
// Need to produce some output otherwise an
// IllegalstateException will be thrown
out.add(Unpooled.EMPTY_BUFFER);
}
}
} else {
throw new Error();
Expand Down

0 comments on commit 66c4c07

Please sign in to comment.