use of org.eclipse.jetty.websocket.api.extensions.ExtensionConfig in project jetty.project by eclipse.
the class PerMessageDeflateExtensionTest method getNegotiatedExtensionList.
private String getNegotiatedExtensionList(Session session) {
StringBuilder actual = new StringBuilder();
actual.append('[');
boolean delim = false;
for (ExtensionConfig ext : session.getUpgradeResponse().getExtensions()) {
if (delim)
actual.append(", ");
actual.append(ext.getName());
delim = true;
}
actual.append(']');
return actual.toString();
}
use of org.eclipse.jetty.websocket.api.extensions.ExtensionConfig in project jetty.project by eclipse.
the class DeflateFrameExtensionTest method init.
private void init(DeflateFrameExtension ext) {
ext.setConfig(new ExtensionConfig(ext.getName()));
ext.setBufferPool(bufferPool);
}
use of org.eclipse.jetty.websocket.api.extensions.ExtensionConfig in project jetty.project by eclipse.
the class DeflateFrameExtensionTest method assertIncoming.
private void assertIncoming(byte[] raw, String... expectedTextDatas) {
WebSocketPolicy policy = WebSocketPolicy.newClientPolicy();
DeflateFrameExtension ext = new DeflateFrameExtension();
ext.setBufferPool(bufferPool);
ext.setPolicy(policy);
ExtensionConfig config = ExtensionConfig.parse("deflate-frame");
ext.setConfig(config);
// Setup capture of incoming frames
IncomingFramesCapture capture = new IncomingFramesCapture();
// Wire up stack
ext.setNextIncomingFrames(capture);
Parser parser = new UnitParser(policy);
parser.configureFromExtensions(Collections.singletonList(ext));
parser.setIncomingFramesHandler(ext);
parser.parse(ByteBuffer.wrap(raw));
int len = expectedTextDatas.length;
capture.assertFrameCount(len);
capture.assertHasFrame(OpCode.TEXT, len);
int i = 0;
for (WebSocketFrame actual : capture.getFrames()) {
String prefix = "Frame[" + i + "]";
Assert.assertThat(prefix + ".opcode", actual.getOpCode(), is(OpCode.TEXT));
Assert.assertThat(prefix + ".fin", actual.isFin(), is(true));
// RSV1 should be unset at this point
Assert.assertThat(prefix + ".rsv1", actual.isRsv1(), is(false));
Assert.assertThat(prefix + ".rsv2", actual.isRsv2(), is(false));
Assert.assertThat(prefix + ".rsv3", actual.isRsv3(), is(false));
ByteBuffer expected = BufferUtil.toBuffer(expectedTextDatas[i], StandardCharsets.UTF_8);
Assert.assertThat(prefix + ".payloadLength", actual.getPayloadLength(), is(expected.remaining()));
ByteBufferAssert.assertEquals(prefix + ".payload", expected, actual.getPayload().slice());
i++;
}
}
use of org.eclipse.jetty.websocket.api.extensions.ExtensionConfig in project jetty.project by eclipse.
the class DeflateFrameExtensionTest method assertOutgoing.
private void assertOutgoing(String text, String expectedHex) throws IOException {
WebSocketPolicy policy = WebSocketPolicy.newClientPolicy();
DeflateFrameExtension ext = new DeflateFrameExtension();
ext.setBufferPool(bufferPool);
ext.setPolicy(policy);
ExtensionConfig config = ExtensionConfig.parse("deflate-frame");
ext.setConfig(config);
Generator generator = new Generator(policy, bufferPool, true);
generator.configureFromExtensions(Collections.singletonList(ext));
OutgoingNetworkBytesCapture capture = new OutgoingNetworkBytesCapture(generator);
ext.setNextOutgoingFrames(capture);
Frame frame = new TextFrame().setPayload(text);
ext.outgoingFrame(frame, null, BatchMode.OFF);
capture.assertBytes(0, expectedHex);
}
use of org.eclipse.jetty.websocket.api.extensions.ExtensionConfig in project jetty.project by eclipse.
the class PerMessageDeflateExtensionTest method testIncomingUncompressedFrames.
/**
* Verify that incoming uncompressed frames are properly passed through
*/
@Test
public void testIncomingUncompressedFrames() {
PerMessageDeflateExtension ext = new PerMessageDeflateExtension();
ext.setBufferPool(bufferPool);
ext.setPolicy(WebSocketPolicy.newServerPolicy());
ExtensionConfig config = ExtensionConfig.parse("permessage-deflate");
ext.setConfig(config);
// Setup capture of incoming frames
IncomingFramesCapture capture = new IncomingFramesCapture();
// Wire up stack
ext.setNextIncomingFrames(capture);
// Quote
List<String> quote = new ArrayList<>();
quote.add("No amount of experimentation can ever prove me right;");
quote.add("a single experiment can prove me wrong.");
quote.add("-- Albert Einstein");
// leave frames as-is, no compression, and pass into extension
for (String q : quote) {
TextFrame frame = new TextFrame().setPayload(q);
// indication to extension that frame is not compressed (ie: a normal frame)
frame.setRsv1(false);
ext.incomingFrame(frame);
}
int len = quote.size();
capture.assertFrameCount(len);
capture.assertHasFrame(OpCode.TEXT, len);
String prefix;
int i = 0;
for (WebSocketFrame actual : capture.getFrames()) {
prefix = "Frame[" + i + "]";
Assert.assertThat(prefix + ".opcode", actual.getOpCode(), is(OpCode.TEXT));
Assert.assertThat(prefix + ".fin", actual.isFin(), is(true));
Assert.assertThat(prefix + ".rsv1", actual.isRsv1(), is(false));
Assert.assertThat(prefix + ".rsv2", actual.isRsv2(), is(false));
Assert.assertThat(prefix + ".rsv3", actual.isRsv3(), is(false));
ByteBuffer expected = BufferUtil.toBuffer(quote.get(i), StandardCharsets.UTF_8);
Assert.assertThat(prefix + ".payloadLength", actual.getPayloadLength(), is(expected.remaining()));
ByteBufferAssert.assertEquals(prefix + ".payload", expected, actual.getPayload().slice());
i++;
}
}
Aggregations