diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectDecoder.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectDecoder.java index 5e1c07076a..15798abbee 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectDecoder.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectDecoder.java @@ -438,7 +438,10 @@ public abstract class HttpObjectDecoder extends ReplayingDecoder\r\n" + + "400 Bad Request\r\n" + + "\r\n" + + "

400 Bad Request

\r\n" + + "
nginx/1.1.19
\r\n" + + "\r\n" + + "\r\n").getBytes(); + + EmbeddedChannel ch = new EmbeddedChannel(new HttpResponseDecoder()); + + ch.writeInbound(Unpooled.wrappedBuffer(data)); + + // Garbage input should generate the 999 Unknown response. + HttpResponse res = ch.readInbound(); + assertThat(res.getProtocolVersion(), sameInstance(HttpVersion.HTTP_1_0)); + assertThat(res.getStatus().code(), is(999)); + assertThat(res.getDecoderResult().isFailure(), is(true)); + assertThat(res.getDecoderResult().isFinished(), is(true)); + assertThat(ch.readInbound(), is(nullValue())); + + // More garbage should not generate anything (i.e. the decoder discards anything beyond this point.) + ch.writeInbound(Unpooled.wrappedBuffer(data)); + assertThat(ch.readInbound(), is(nullValue())); + + // Closing the connection should not generate anything since the protocol has been violated. + ch.finish(); + assertThat(ch.readInbound(), is(nullValue())); + } }