Search in sources :

Example 1 with Entry

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);
}
Also used : Entry(org.eclipse.jetty.http2.hpack.HpackContext.Entry) HttpField(org.eclipse.jetty.http.HttpField) Test(org.junit.Test)

Example 2 with Entry

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);
    }
}
Also used : Entry(org.eclipse.jetty.http2.hpack.HpackContext.Entry) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 3 with Entry

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: "));
}
Also used : Entry(org.eclipse.jetty.http2.hpack.HpackContext.Entry) Test(org.junit.Test)

Example 4 with Entry

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();
}
Also used : PriorityFrame(org.eclipse.jetty.http2.frames.PriorityFrame) HeadersFrame(org.eclipse.jetty.http2.frames.HeadersFrame) EndPoint(org.eclipse.jetty.io.EndPoint)

Example 5 with Entry

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);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SettingsFrame(org.eclipse.jetty.http2.frames.SettingsFrame) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) EndPoint(org.eclipse.jetty.io.EndPoint)

Aggregations

Entry (org.eclipse.jetty.http2.hpack.HpackContext.Entry)9 HttpField (org.eclipse.jetty.http.HttpField)7 Test (org.junit.Test)7 EndPoint (org.eclipse.jetty.io.EndPoint)3 HttpHeader (org.eclipse.jetty.http.HttpHeader)2 ByteBuffer (java.nio.ByteBuffer)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 BadMessageException (org.eclipse.jetty.http.BadMessageException)1 PreEncodedHttpField (org.eclipse.jetty.http.PreEncodedHttpField)1 HeadersFrame (org.eclipse.jetty.http2.frames.HeadersFrame)1 PriorityFrame (org.eclipse.jetty.http2.frames.PriorityFrame)1 PushPromiseFrame (org.eclipse.jetty.http2.frames.PushPromiseFrame)1 SettingsFrame (org.eclipse.jetty.http2.frames.SettingsFrame)1 StaticEntry (org.eclipse.jetty.http2.hpack.HpackContext.StaticEntry)1