[#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:
parent
7884574c7b
commit
73c35aef4e
@ -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;
|
||||||
|
@ -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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user