This is an automated email from the ASF dual-hosted git repository. elecharny pushed a commit to branch 2.0.X in repository https://gitbox.apache.org/repos/asf/mina.git
The following commit(s) were added to refs/heads/2.0.X by this push: new 4ee362f Backported Wim van Ravesteijn test 4ee362f is described below commit 4ee362f6203194476aa5230b2f2a76d3a5aa41aa Author: emmanuel lecharny <elecha...@apache.org> AuthorDate: Tue Feb 8 18:55:00 2022 +0100 Backported Wim van Ravesteijn test --- .../apache/mina/http/HttpServerDecoderTest.java | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/mina-http/src/test/java/org/apache/mina/http/HttpServerDecoderTest.java b/mina-http/src/test/java/org/apache/mina/http/HttpServerDecoderTest.java index 45405a0..6adbae6 100644 --- a/mina-http/src/test/java/org/apache/mina/http/HttpServerDecoderTest.java +++ b/mina-http/src/test/java/org/apache/mina/http/HttpServerDecoderTest.java @@ -20,6 +20,7 @@ package org.apache.mina.http; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; import java.nio.charset.CharacterCodingException; @@ -37,6 +38,8 @@ import org.apache.mina.http.api.HttpRequest; import org.junit.Test; public class HttpServerDecoderTest { + private static final String DECODER_STATE_ATT = "http.ds"; + private static final CharsetEncoder encoder = Charset.forName("US-ASCII").newEncoder(); //$NON-NLS-1$ private static final ProtocolDecoder decoder = new HttpServerDecoder(); @@ -321,4 +324,29 @@ public class HttpServerDecoderTest { assertEquals("localhost", request.getHeader("host")); assertTrue(out.getMessageQueue().poll() instanceof HttpEndOfContent); } + + @Test + public void dosOnRequestWithAdditionalData() throws Exception { + AbstractProtocolDecoderOutput out = new AbstractProtocolDecoderOutput() { + public void flush(NextFilter nextFilter, IoSession session) { + } + }; + + IoBuffer buffer = IoBuffer.allocate(0).setAutoExpand(true); + buffer.putString("GET / HTTP/1.0\r\nHost:localhost \r\n\r\ndummy", encoder); + buffer.rewind(); + int prevBufferPosition = buffer.position(); + + while (buffer.hasRemaining()) { + decoder.decode(session, buffer, out); + assertNotEquals("Buffer at new position", prevBufferPosition, buffer.position()); + prevBufferPosition = buffer.position(); + } + + assertEquals(2, out.getMessageQueue().size()); + HttpRequest request = (HttpRequest) out.getMessageQueue().poll(); + assertEquals("localhost", request.getHeader("host")); + assertTrue(out.getMessageQueue().poll() instanceof HttpEndOfContent); + session.removeAttribute(DECODER_STATE_ATT); // This test leaves session in HEAD state, crashing following test + } }