diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/HttpRequestDecoderTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/HttpRequestDecoderTest.java index 77f98dc0e5..4689e64a97 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/HttpRequestDecoderTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/HttpRequestDecoderTest.java @@ -17,11 +17,13 @@ package io.netty.handler.codec.http; import io.netty.buffer.Unpooled; import io.netty.channel.embedded.EmbeddedChannel; +import io.netty.util.AsciiString; import io.netty.util.CharsetUtil; import org.junit.Test; import java.util.List; +import static io.netty.handler.codec.http.HttpHeaderNames.*; import static io.netty.handler.codec.http.HttpHeadersTestUtils.of; import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.is; @@ -237,4 +239,35 @@ public class HttpRequestDecoderTest { assertThat(channel.finish(), is(false)); } + + @Test + public void testMessagesSplitBetweenMultipleBuffers() { + EmbeddedChannel channel = new EmbeddedChannel(new HttpRequestDecoder()); + String crlf = "\r\n"; + String str1 = "GET /some/path HTTP/1.1" + crlf + + "Host: localhost1" + crlf + crlf + + "GET /some/other/path HTTP/1.0" + crlf + + "Hos"; + String str2 = "t: localhost2" + crlf + + "content-length: 0" + crlf + crlf; + channel.writeInbound(Unpooled.copiedBuffer(str1, CharsetUtil.US_ASCII)); + HttpRequest req = channel.readInbound(); + assertEquals(HttpVersion.HTTP_1_1, req.protocolVersion()); + assertEquals("/some/path", req.uri()); + assertEquals(1, req.headers().size()); + assertTrue(AsciiString.contentEqualsIgnoreCase("localhost1", req.headers().get(HOST))); + LastHttpContent cnt = channel.readInbound(); + cnt.release(); + + channel.writeInbound(Unpooled.copiedBuffer(str2, CharsetUtil.US_ASCII)); + req = channel.readInbound(); + assertEquals(HttpVersion.HTTP_1_0, req.protocolVersion()); + assertEquals("/some/other/path", req.uri()); + assertEquals(2, req.headers().size()); + assertTrue(AsciiString.contentEqualsIgnoreCase("localhost2", req.headers().get(HOST))); + assertTrue(AsciiString.contentEqualsIgnoreCase("0", req.headers().get(HttpHeaderNames.CONTENT_LENGTH))); + cnt = channel.readInbound(); + cnt.release(); + assertFalse(channel.finishAndReleaseAll()); + } }