This commit is contained in:
parent
bc141f695b
commit
e02225a80f
@ -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"
|
||||
+ "<html><body></body></html>\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<ChannelBuffer> decoder = new DecoderEmbedder<ChannelBuffer>(codec);
|
||||
EncoderEmbedder<ChannelBuffer> encoder = new EncoderEmbedder<ChannelBuffer>(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<ChannelBuffer> decoder = new DecoderEmbedder<ChannelBuffer>(codec);
|
||||
|
||||
EncoderEmbedder<ChannelBuffer> encoder = new EncoderEmbedder<ChannelBuffer>(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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user