[#1101] Fix NPE which accour when send a 100-continue response and using the HttpContentEncoder

This commit is contained in:
Norman Maurer 2013-02-28 07:13:21 +01:00
parent 977b6f3a28
commit b6038534cc

View File

@ -54,7 +54,7 @@ public abstract class HttpContentEncoder extends MessageToMessageCodec<HttpMessa
private EmbeddedByteChannel encoder; private EmbeddedByteChannel encoder;
private HttpMessage message; private HttpMessage message;
private boolean encodeStarted; private boolean encodeStarted;
private boolean continueResponse;
@Override @Override
protected Object decode(ChannelHandlerContext ctx, HttpMessage msg) protected Object decode(ChannelHandlerContext ctx, HttpMessage msg)
throws Exception { throws Exception {
@ -71,6 +71,18 @@ public abstract class HttpContentEncoder extends MessageToMessageCodec<HttpMessa
protected Object encode(ChannelHandlerContext ctx, HttpObject msg) protected Object encode(ChannelHandlerContext ctx, HttpObject msg)
throws Exception { throws Exception {
if (msg instanceof HttpResponse && ((HttpResponse) msg).getStatus().code() == 100) { if (msg instanceof HttpResponse && ((HttpResponse) msg).getStatus().code() == 100) {
// 100-continue response must be passed through.
BufUtil.retain(msg);
if (!(msg instanceof LastHttpContent)) {
continueResponse = true;
}
return msg;
}
if (continueResponse) {
if (msg instanceof LastHttpContent) {
continueResponse = false;
}
// 100-continue response must be passed through. // 100-continue response must be passed through.
BufUtil.retain(msg); BufUtil.retain(msg);
return msg; return msg;