diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/HttpClientCodecTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/HttpClientCodecTest.java index e53edc08d5..2f4ac8ba98 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/HttpClientCodecTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/HttpClientCodecTest.java @@ -31,6 +31,10 @@ public class HttpClientCodecTest { private static final String RESPONSE = "HTTP/1.0 200 OK\r\n" + "Date: Fri, 31 Dec 1999 23:59:59 GMT\r\n" + "Content-Type: text/html\r\n" + "Content-Length: 28\r\n" + "\r\n" + "\r\n"; + private static final String INCOMPLETE_CHUNKED_RESPONSE = "HTTP/1.1 200 OK\r\n" + "Content-Type: text/plain\r\n" + "Transfer-Encoding: chunked\r\n" + "\r\n" + +"5\r\n" + "first\r\n" + "6\r\n" + "second\r\n" + "0\r\n"; + private static final String CHUNKED_RESPONSE = INCOMPLETE_CHUNKED_RESPONSE + "\r\n"; + @Test public void testFailsNotOnRequestResponse() { @@ -46,6 +50,20 @@ public class HttpClientCodecTest { } + @Test + public void testFailsNotOnRequestResponseChunked() { + HttpClientCodec codec = new HttpClientCodec(); + DecoderEmbedder decoder = new DecoderEmbedder(codec); + EncoderEmbedder encoder = new EncoderEmbedder(codec); + + encoder.offer(new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "http://localhost/")); + decoder.offer(ChannelBuffers.copiedBuffer(CHUNKED_RESPONSE, CharsetUtil.ISO_8859_1)); + + encoder.finish(); + decoder.finish(); + + } + @Test public void testFailsOnMissingResponse() { HttpClientCodec codec = new HttpClientCodec(); @@ -61,4 +79,24 @@ public class HttpClientCodecTest { } } + + @Test + public void testFailsOnIncompleteChunkedResponse() { + HttpClientCodec codec = new HttpClientCodec(); + DecoderEmbedder decoder = new DecoderEmbedder(codec); + + EncoderEmbedder encoder = new EncoderEmbedder(codec); + + encoder.offer(new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "http://localhost/")); + decoder.offer(ChannelBuffers.copiedBuffer(INCOMPLETE_CHUNKED_RESPONSE, CharsetUtil.ISO_8859_1)); + + try { + encoder.finish(); + decoder.finish(); + fail(); + } catch (CodecEmbedderException e) { + assertTrue(e.getCause() instanceof PrematureChannelClosureException); + } + + } }