2020package org .apache .mina .http ;
2121
2222import static org .junit .Assert .assertEquals ;
23+ import static org .junit .Assert .assertNotEquals ;
2324import static org .junit .Assert .assertTrue ;
2425
2526import java .nio .charset .CharacterCodingException ;
@@ -41,6 +42,8 @@ public class HttpServerDecoderTest {
4142
4243 private static final ProtocolDecoder decoder = new HttpServerDecoder ();
4344
45+ private static final String DECODER_STATE_ATT = "http.ds" ;
46+
4447 /*
4548 * Use a single session for all requests in order to test state management better
4649 */
@@ -295,4 +298,26 @@ public void flush(NextFilter nextFilter, IoSession session) {
295298 assertEquals ("localhost" , request .getHeader ("host" ));
296299 assertTrue (out .getMessageQueue ().poll () instanceof HttpEndOfContent );
297300 }
301+
302+ @ Test
303+ public void dosOnRequestWithAdditionalData () throws Exception {
304+ AbstractProtocolDecoderOutput out = new AbstractProtocolDecoderOutput () {
305+ public void flush (NextFilter nextFilter , IoSession session ) {
306+ }
307+ };
308+ IoBuffer buffer = IoBuffer .allocate (0 ).setAutoExpand (true );
309+ buffer .putString ("GET / HTTP/1.0\r \n Host:localhost \r \n \r \n dummy" , encoder );
310+ buffer .rewind ();
311+ int prevBufferPosition = buffer .position ();
312+ while (buffer .hasRemaining ()) {
313+ decoder .decode (session , buffer , out );
314+ assertNotEquals ("Buffer at new position" , prevBufferPosition , buffer .position ());
315+ prevBufferPosition = buffer .position ();
316+ }
317+ assertEquals (2 , out .getMessageQueue ().size ());
318+ HttpRequest request = (HttpRequest ) out .getMessageQueue ().poll ();
319+ assertEquals ("localhost" , request .getHeader ("host" ));
320+ assertTrue (out .getMessageQueue ().poll () instanceof HttpEndOfContent );
321+ session .removeAttribute (DECODER_STATE_ATT ); // This test leaves session in HEAD state, crashing following test
322+ }
298323}
0 commit comments