use of org.eclipse.jetty.http2.hpack.HpackContext.Entry in project jetty.project by eclipse.
the class HpackContextTest method testGetAddStatic.
@Test
public void testGetAddStatic() {
HpackContext ctx = new HpackContext(4096);
// Look for the field. Should find static version.
HttpField methodGet = new HttpField(":method", "GET");
assertEquals(methodGet, ctx.get(methodGet).getHttpField());
assertTrue(ctx.get(methodGet).isStatic());
// Add static version to dynamic table
Entry e0 = ctx.add(ctx.get(methodGet).getHttpField());
// Look again and should see dynamic version
assertEquals(methodGet, ctx.get(methodGet).getHttpField());
assertFalse(methodGet == ctx.get(methodGet).getHttpField());
assertFalse(ctx.get(methodGet).isStatic());
// Duplicates allows
Entry e1 = ctx.add(ctx.get(methodGet).getHttpField());
// Look again and should see dynamic version
assertEquals(methodGet, ctx.get(methodGet).getHttpField());
assertFalse(methodGet == ctx.get(methodGet).getHttpField());
assertFalse(ctx.get(methodGet).isStatic());
assertFalse(e0 == e1);
}
use of org.eclipse.jetty.http2.hpack.HpackContext.Entry in project jetty.project by eclipse.
the class HpackContextTest method testStaticHuffmanValues.
@Test
public void testStaticHuffmanValues() {
HpackContext ctx = new HpackContext(4096);
for (int i = 2; i <= 14; i++) {
Entry entry = ctx.get(i);
assertTrue(entry.isStatic());
ByteBuffer buffer = ByteBuffer.wrap(entry.getStaticHuffmanValue());
int huff = 0xff & buffer.get();
assertTrue((0x80 & huff) == 0x80);
int len = NBitInteger.decode(buffer, 7);
assertEquals(len, buffer.remaining());
String value = Huffman.decode(buffer);
assertEquals(entry.getHttpField().getValue(), value);
}
}
use of org.eclipse.jetty.http2.hpack.HpackContext.Entry in project jetty.project by eclipse.
the class HpackContextTest method testStaticName.
@Test
public void testStaticName() {
HpackContext ctx = new HpackContext(4096);
Entry entry = ctx.get(":method");
assertEquals(":method", entry.getHttpField().getName());
Assert.assertTrue(entry.isStatic());
Assert.assertThat(entry.toString(), Matchers.startsWith("{S,2,:method: "));
}
use of org.eclipse.jetty.http2.hpack.HpackContext.Entry in project jetty.project by eclipse.
the class HTTP2Session method newStream.
@Override
public void newStream(HeadersFrame frame, Promise<Stream> promise, Stream.Listener listener) {
// Synchronization is necessary to atomically create
// the stream id and enqueue the frame to be sent.
boolean queued;
synchronized (this) {
int streamId = frame.getStreamId();
if (streamId <= 0) {
streamId = streamIds.getAndAdd(2);
PriorityFrame priority = frame.getPriority();
priority = priority == null ? null : new PriorityFrame(streamId, priority.getParentStreamId(), priority.getWeight(), priority.isExclusive());
frame = new HeadersFrame(streamId, frame.getMetaData(), priority, frame.isEndStream());
}
final IStream stream = createLocalStream(streamId, promise);
if (stream == null)
return;
stream.setListener(listener);
ControlEntry entry = new ControlEntry(frame, stream, new PromiseCallback<>(promise, stream));
queued = flusher.append(entry);
}
// Iterate outside the synchronized block.
if (queued)
flusher.iterate();
}
use of org.eclipse.jetty.http2.hpack.HpackContext.Entry in project jetty.project by eclipse.
the class HTTP2Session method onSettings.
public void onSettings(SettingsFrame frame, boolean reply) {
if (LOG.isDebugEnabled())
LOG.debug("Received {}", frame);
if (frame.isReply())
return;
// Iterate over all settings
for (Map.Entry<Integer, Integer> entry : frame.getSettings().entrySet()) {
int key = entry.getKey();
int value = entry.getValue();
switch(key) {
case SettingsFrame.HEADER_TABLE_SIZE:
{
if (LOG.isDebugEnabled())
LOG.debug("Update HPACK header table size to {} for {}", value, this);
generator.setHeaderTableSize(value);
break;
}
case SettingsFrame.ENABLE_PUSH:
{
// SPEC: check the value is sane.
if (value != 0 && value != 1) {
onConnectionFailure(ErrorCode.PROTOCOL_ERROR.code, "invalid_settings_enable_push");
return;
}
pushEnabled = value == 1;
if (LOG.isDebugEnabled())
LOG.debug("{} push for {}", pushEnabled ? "Enable" : "Disable", this);
break;
}
case SettingsFrame.MAX_CONCURRENT_STREAMS:
{
maxLocalStreams = value;
if (LOG.isDebugEnabled())
LOG.debug("Update max local concurrent streams to {} for {}", maxLocalStreams, this);
break;
}
case SettingsFrame.INITIAL_WINDOW_SIZE:
{
if (LOG.isDebugEnabled())
LOG.debug("Update initial window size to {} for {}", value, this);
flowControl.updateInitialStreamWindow(this, value, false);
break;
}
case SettingsFrame.MAX_FRAME_SIZE:
{
if (LOG.isDebugEnabled())
LOG.debug("Update max frame size to {} for {}", value, this);
// SPEC: check the max frame size is sane.
if (value < Frame.DEFAULT_MAX_LENGTH || value > Frame.MAX_MAX_LENGTH) {
onConnectionFailure(ErrorCode.PROTOCOL_ERROR.code, "invalid_settings_max_frame_size");
return;
}
generator.setMaxFrameSize(value);
break;
}
case SettingsFrame.MAX_HEADER_LIST_SIZE:
{
if (LOG.isDebugEnabled())
LOG.debug("Update max header list size to {} for {}", value, this);
generator.setMaxHeaderListSize(value);
break;
}
default:
{
if (LOG.isDebugEnabled())
LOG.debug("Unknown setting {}:{} for {}", key, value, this);
break;
}
}
}
notifySettings(this, frame);
if (reply) {
SettingsFrame replyFrame = new SettingsFrame(Collections.emptyMap(), true);
settings(replyFrame, Callback.NOOP);
}
}
Aggregations