use of io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame in project netty by netty.
the class WebSocketExtensionFilterTest method testNeverSkip.
@Test
public void testNeverSkip() {
WebSocketExtensionFilter neverSkip = WebSocketExtensionFilter.NEVER_SKIP;
BinaryWebSocketFrame binaryFrame = new BinaryWebSocketFrame();
assertFalse(neverSkip.mustSkip(binaryFrame));
assertTrue(binaryFrame.release());
TextWebSocketFrame textFrame = new TextWebSocketFrame();
assertFalse(neverSkip.mustSkip(textFrame));
assertTrue(textFrame.release());
PingWebSocketFrame pingFrame = new PingWebSocketFrame();
assertFalse(neverSkip.mustSkip(pingFrame));
assertTrue(pingFrame.release());
PongWebSocketFrame pongFrame = new PongWebSocketFrame();
assertFalse(neverSkip.mustSkip(pongFrame));
assertTrue(pongFrame.release());
CloseWebSocketFrame closeFrame = new CloseWebSocketFrame();
assertFalse(neverSkip.mustSkip(closeFrame));
assertTrue(closeFrame.release());
ContinuationWebSocketFrame continuationFrame = new ContinuationWebSocketFrame();
assertFalse(neverSkip.mustSkip(continuationFrame));
assertTrue(continuationFrame.release());
}
use of io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame in project netty by netty.
the class PerFrameDeflateDecoderTest method testCompressedFrame.
@Test
public void testCompressedFrame() {
EmbeddedChannel encoderChannel = new EmbeddedChannel(ZlibCodecFactory.newZlibEncoder(ZlibWrapper.NONE, 9, 15, 8));
EmbeddedChannel decoderChannel = new EmbeddedChannel(new PerFrameDeflateDecoder(false));
// initialize
byte[] payload = new byte[300];
random.nextBytes(payload);
assertTrue(encoderChannel.writeOutbound(Unpooled.wrappedBuffer(payload)));
ByteBuf compressedPayload = encoderChannel.readOutbound();
BinaryWebSocketFrame compressedFrame = new BinaryWebSocketFrame(true, RSV1 | RSV3, compressedPayload.slice(0, compressedPayload.readableBytes() - 4));
// execute
assertTrue(decoderChannel.writeInbound(compressedFrame));
BinaryWebSocketFrame uncompressedFrame = decoderChannel.readInbound();
// test
assertNotNull(uncompressedFrame);
assertNotNull(uncompressedFrame.content());
assertEquals(RSV3, uncompressedFrame.rsv());
assertEquals(300, uncompressedFrame.content().readableBytes());
byte[] finalPayload = new byte[300];
uncompressedFrame.content().readBytes(finalPayload);
assertArrayEquals(finalPayload, payload);
uncompressedFrame.release();
}
use of io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame in project netty by netty.
the class PerMessageDeflateDecoderTest method testNormalFrame.
@Test
public void testNormalFrame() {
EmbeddedChannel decoderChannel = new EmbeddedChannel(new PerMessageDeflateDecoder(false));
// initialize
byte[] payload = new byte[300];
random.nextBytes(payload);
BinaryWebSocketFrame frame = new BinaryWebSocketFrame(true, WebSocketExtension.RSV3, Unpooled.wrappedBuffer(payload));
// execute
assertTrue(decoderChannel.writeInbound(frame));
BinaryWebSocketFrame newFrame = decoderChannel.readInbound();
// test
assertNotNull(newFrame);
assertNotNull(newFrame.content());
assertEquals(WebSocketExtension.RSV3, newFrame.rsv());
assertEquals(300, newFrame.content().readableBytes());
byte[] finalPayload = new byte[300];
newFrame.content().readBytes(finalPayload);
assertArrayEquals(finalPayload, payload);
newFrame.release();
}
use of io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame in project netty by netty.
the class PerMessageDeflateDecoderTest method testDecompressionSkipForBinaryFrame.
@Test
public void testDecompressionSkipForBinaryFrame() {
EmbeddedChannel encoderChannel = new EmbeddedChannel(ZlibCodecFactory.newZlibEncoder(ZlibWrapper.NONE, 9, 15, 8));
EmbeddedChannel decoderChannel = new EmbeddedChannel(new PerMessageDeflateDecoder(false, ALWAYS_SKIP));
byte[] payload = new byte[300];
random.nextBytes(payload);
assertTrue(encoderChannel.writeOutbound(Unpooled.wrappedBuffer(payload)));
ByteBuf compressedPayload = encoderChannel.readOutbound();
BinaryWebSocketFrame compressedBinaryFrame = new BinaryWebSocketFrame(true, WebSocketExtension.RSV1, compressedPayload);
assertTrue(decoderChannel.writeInbound(compressedBinaryFrame));
WebSocketFrame inboundFrame = decoderChannel.readInbound();
assertEquals(WebSocketExtension.RSV1, inboundFrame.rsv());
assertEquals(compressedPayload, inboundFrame.content());
assertTrue(inboundFrame.release());
assertTrue(encoderChannel.finishAndReleaseAll());
assertFalse(decoderChannel.finish());
}
use of io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame in project netty by netty.
the class PerMessageDeflateDecoderTest method testSelectivityDecompressionSkip.
@Test
public void testSelectivityDecompressionSkip() {
WebSocketExtensionFilter selectivityDecompressionFilter = new WebSocketExtensionFilter() {
@Override
public boolean mustSkip(WebSocketFrame frame) {
return frame instanceof TextWebSocketFrame && frame.content().readableBytes() < 100;
}
};
EmbeddedChannel encoderChannel = new EmbeddedChannel(ZlibCodecFactory.newZlibEncoder(ZlibWrapper.NONE, 9, 15, 8));
EmbeddedChannel decoderChannel = new EmbeddedChannel(new PerMessageDeflateDecoder(false, selectivityDecompressionFilter));
String textPayload = "compressed payload";
byte[] binaryPayload = new byte[300];
random.nextBytes(binaryPayload);
assertTrue(encoderChannel.writeOutbound(Unpooled.wrappedBuffer(textPayload.getBytes(UTF_8))));
assertTrue(encoderChannel.writeOutbound(Unpooled.wrappedBuffer(binaryPayload)));
ByteBuf compressedTextPayload = encoderChannel.readOutbound();
ByteBuf compressedBinaryPayload = encoderChannel.readOutbound();
TextWebSocketFrame compressedTextFrame = new TextWebSocketFrame(true, WebSocketExtension.RSV1, compressedTextPayload);
BinaryWebSocketFrame compressedBinaryFrame = new BinaryWebSocketFrame(true, WebSocketExtension.RSV1, compressedBinaryPayload);
assertTrue(decoderChannel.writeInbound(compressedTextFrame));
assertTrue(decoderChannel.writeInbound(compressedBinaryFrame));
TextWebSocketFrame inboundTextFrame = decoderChannel.readInbound();
BinaryWebSocketFrame inboundBinaryFrame = decoderChannel.readInbound();
assertEquals(WebSocketExtension.RSV1, inboundTextFrame.rsv());
assertEquals(compressedTextPayload, inboundTextFrame.content());
assertTrue(inboundTextFrame.release());
assertEquals(0, inboundBinaryFrame.rsv());
assertArrayEquals(binaryPayload, ByteBufUtil.getBytes(inboundBinaryFrame.content()));
assertTrue(inboundBinaryFrame.release());
assertTrue(encoderChannel.finishAndReleaseAll());
assertFalse(decoderChannel.finish());
}
Aggregations