use of org.eclipse.jetty.http2.generator.SettingsGenerator in project jetty.project by eclipse.
the class SettingsGenerateParseTest method testGenerateParseInvalidSettings.
@Test
public void testGenerateParseInvalidSettings() throws Exception {
SettingsGenerator generator = new SettingsGenerator(new HeaderGenerator());
final AtomicInteger errorRef = new AtomicInteger();
Parser parser = new Parser(byteBufferPool, new Parser.Listener.Adapter() {
@Override
public void onConnectionFailure(int error, String reason) {
errorRef.set(error);
}
}, 4096, 8192);
Map<Integer, Integer> settings1 = new HashMap<>();
settings1.put(13, 17);
ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool);
generator.generateSettings(lease, settings1, true);
// Modify the length of the frame to make it invalid
ByteBuffer bytes = lease.getByteBuffers().get(0);
bytes.putShort(1, (short) (bytes.getShort(1) - 1));
for (ByteBuffer buffer : lease.getByteBuffers()) {
while (buffer.hasRemaining()) {
parser.parse(ByteBuffer.wrap(new byte[] { buffer.get() }));
}
}
Assert.assertEquals(ErrorCode.FRAME_SIZE_ERROR.code, errorRef.get());
}
use of org.eclipse.jetty.http2.generator.SettingsGenerator in project jetty.project by eclipse.
the class SettingsGenerateParseTest method testGenerateParseOneByteAtATime.
@Test
public void testGenerateParseOneByteAtATime() throws Exception {
SettingsGenerator generator = new SettingsGenerator(new HeaderGenerator());
final List<SettingsFrame> frames = new ArrayList<>();
Parser parser = new Parser(byteBufferPool, new Parser.Listener.Adapter() {
@Override
public void onSettings(SettingsFrame frame) {
frames.add(frame);
}
}, 4096, 8192);
Map<Integer, Integer> settings1 = new HashMap<>();
int key = 13;
Integer value = 17;
settings1.put(key, value);
// Iterate a few times to be sure generator and parser are properly reset.
for (int i = 0; i < 2; ++i) {
ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool);
generator.generateSettings(lease, settings1, true);
frames.clear();
for (ByteBuffer buffer : lease.getByteBuffers()) {
while (buffer.hasRemaining()) {
parser.parse(ByteBuffer.wrap(new byte[] { buffer.get() }));
}
}
Assert.assertEquals(1, frames.size());
SettingsFrame frame = frames.get(0);
Map<Integer, Integer> settings2 = frame.getSettings();
Assert.assertEquals(1, settings2.size());
Assert.assertEquals(value, settings2.get(key));
Assert.assertTrue(frame.isReply());
}
}
use of org.eclipse.jetty.http2.generator.SettingsGenerator in project jetty.project by eclipse.
the class SettingsGenerateParseTest method testGenerateParse.
private List<SettingsFrame> testGenerateParse(Map<Integer, Integer> settings) {
SettingsGenerator generator = new SettingsGenerator(new HeaderGenerator());
final List<SettingsFrame> frames = new ArrayList<>();
Parser parser = new Parser(byteBufferPool, new Parser.Listener.Adapter() {
@Override
public void onSettings(SettingsFrame frame) {
frames.add(frame);
}
}, 4096, 8192);
// Iterate a few times to be sure generator and parser are properly reset.
for (int i = 0; i < 2; ++i) {
ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool);
generator.generateSettings(lease, settings, true);
frames.clear();
for (ByteBuffer buffer : lease.getByteBuffers()) {
while (buffer.hasRemaining()) {
parser.parse(buffer);
}
}
}
return frames;
}
Aggregations