[#1309] Make sure ReplayDecoder respect isSingleDecode()

* This could cause for example corrupt WebSocketFrame's if they was written from the server
  to the client directly after it send the handshake response.
This commit is contained in:
Norman Maurer 2013-04-25 08:32:07 +02:00
parent 7884574c7b
commit 73c35aef4e
2 changed files with 19 additions and 0 deletions

View File

@ -427,6 +427,9 @@ public abstract class ReplayingDecoder<S> extends ByteToMessageDecoder {
"if it returned a decoded message (caused by: " + "if it returned a decoded message (caused by: " +
getClass() + ')'); getClass() + ')');
} }
if (isSingleDecode()) {
break;
}
} }
} catch (CodecException e) { } catch (CodecException e) {
throw e; throw e;

View File

@ -85,4 +85,20 @@ public class ReplayingDecoderTest {
ctx.pipeline().replace(this, "less-bloated", new LineDecoder()); ctx.pipeline().replace(this, "less-bloated", new LineDecoder());
} }
} }
@Test
public void testSingleDecode() throws Exception {
LineDecoder decoder = new LineDecoder();
decoder.setSingleDecode(true);
EmbeddedByteChannel ch = new EmbeddedByteChannel(decoder);
// "C\n" should be appended to "AB" so that LineDecoder decodes it correctly.
ch.writeInbound(Unpooled.wrappedBuffer(new byte[]{'C', '\n' , 'B', '\n'}));
assertEquals(Unpooled.wrappedBuffer(new byte[] {'C' }), ch.readInbound());
assertNull("Must be null as it must only decode one frame", ch.readInbound());
ch.finish();
assertEquals(Unpooled.wrappedBuffer(new byte[] {'B' }), ch.readInbound());
assertNull(ch.readInbound());
}
} }