Search in sources :

Example 51 with MetaData

use of org.eclipse.jetty.http.MetaData in project jetty.project by eclipse.

the class HpackEncoderTest method testNeverIndexSetCookie.

@Test
public void testNeverIndexSetCookie() {
    HpackEncoder encoder = new HpackEncoder(38 * 5);
    ByteBuffer buffer = BufferUtil.allocate(4096);
    HttpFields fields = new HttpFields();
    fields.put("set-cookie", "some cookie value");
    // encode
    BufferUtil.clearToFill(buffer);
    encoder.encode(buffer, new MetaData(HttpVersion.HTTP_2, fields));
    BufferUtil.flipToFlush(buffer, 0);
    // something was encoded!
    assertThat(buffer.remaining(), Matchers.greaterThan(0));
    // empty dynamic table
    Assert.assertEquals(0, encoder.getHpackContext().size());
    // encode again
    BufferUtil.clearToFill(buffer);
    encoder.encode(buffer, new MetaData(HttpVersion.HTTP_2, fields));
    BufferUtil.flipToFlush(buffer, 0);
    // something was encoded!
    assertThat(buffer.remaining(), Matchers.greaterThan(0));
    // empty dynamic table
    Assert.assertEquals(0, encoder.getHpackContext().size());
}
Also used : MetaData(org.eclipse.jetty.http.MetaData) HttpFields(org.eclipse.jetty.http.HttpFields) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 52 with MetaData

use of org.eclipse.jetty.http.MetaData in project jetty.project by eclipse.

the class HpackPerfTest method encodeStories.

private void encodeStories(ByteBuffer buffer, Map<String, Object>[] stories, String type) throws Exception {
    for (Map<String, Object> story : stories) {
        if (type.equals(story.get("context"))) {
            HpackEncoder encoder = new HpackEncoder(_maxDynamicTableSize, _maxDynamicTableSize);
            // System.err.println(story);
            Object[] cases = (Object[]) story.get("cases");
            for (Object c : cases) {
                // System.err.println("  "+c);
                Object[] headers = (Object[]) ((Map<String, Object>) c).get("headers");
                // System.err.println("    "+headers);
                HttpFields fields = new HttpFields();
                for (Object header : headers) {
                    Map<String, String> h = (Map<String, String>) header;
                    Map.Entry<String, String> e = h.entrySet().iterator().next();
                    fields.add(e.getKey(), e.getValue());
                    _unencodedSize += e.getKey().length() + e.getValue().length();
                }
                BufferUtil.clearToFill(buffer);
                encoder.encode(buffer, new MetaData(HttpVersion.HTTP_2, fields));
                BufferUtil.flipToFlush(buffer, 0);
                _encodedSize += buffer.remaining();
            }
        }
    }
}
Also used : MetaData(org.eclipse.jetty.http.MetaData) HttpFields(org.eclipse.jetty.http.HttpFields) Map(java.util.Map)

Example 53 with MetaData

use of org.eclipse.jetty.http.MetaData in project jetty.project by eclipse.

the class HpackTest method encodeDecodeTooLargeTest.

@Test
public void encodeDecodeTooLargeTest() {
    HpackEncoder encoder = new HpackEncoder();
    HpackDecoder decoder = new HpackDecoder(4096, 164);
    ByteBuffer buffer = BufferUtil.allocate(16 * 1024);
    HttpFields fields0 = new HttpFields();
    fields0.add("1234567890", "1234567890123456789012345678901234567890");
    fields0.add("Cookie", "abcdeffhijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQR");
    MetaData original0 = new MetaData(HttpVersion.HTTP_2, fields0);
    BufferUtil.clearToFill(buffer);
    encoder.encode(buffer, original0);
    BufferUtil.flipToFlush(buffer, 0);
    MetaData decoded0 = (MetaData) decoder.decode(buffer);
    assertMetadataSame(original0, decoded0);
    HttpFields fields1 = new HttpFields();
    fields1.add("1234567890", "1234567890123456789012345678901234567890");
    fields1.add("Cookie", "abcdeffhijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQR");
    fields1.add("x", "y");
    MetaData original1 = new MetaData(HttpVersion.HTTP_2, fields1);
    BufferUtil.clearToFill(buffer);
    encoder.encode(buffer, original1);
    BufferUtil.flipToFlush(buffer, 0);
    try {
        decoder.decode(buffer);
        Assert.fail();
    } catch (BadMessageException e) {
        assertEquals(HttpStatus.REQUEST_HEADER_FIELDS_TOO_LARGE_431, e.getCode());
    }
}
Also used : MetaData(org.eclipse.jetty.http.MetaData) BadMessageException(org.eclipse.jetty.http.BadMessageException) HttpFields(org.eclipse.jetty.http.HttpFields) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 54 with MetaData

use of org.eclipse.jetty.http.MetaData in project jetty.project by eclipse.

the class HpackTest method evictReferencedFieldTest.

@Test
public void evictReferencedFieldTest() {
    HpackEncoder encoder = new HpackEncoder(200, 200);
    HpackDecoder decoder = new HpackDecoder(200, 1024);
    ByteBuffer buffer = BufferUtil.allocate(16 * 1024);
    HttpFields fields0 = new HttpFields();
    fields0.add("123456789012345678901234567890123456788901234567890", "value");
    fields0.add("foo", "abcdeffhijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQR");
    MetaData original0 = new MetaData(HttpVersion.HTTP_2, fields0);
    BufferUtil.clearToFill(buffer);
    encoder.encode(buffer, original0);
    BufferUtil.flipToFlush(buffer, 0);
    MetaData decoded0 = (MetaData) decoder.decode(buffer);
    assertEquals(2, encoder.getHpackContext().size());
    assertEquals(2, decoder.getHpackContext().size());
    assertEquals("123456789012345678901234567890123456788901234567890", encoder.getHpackContext().get(HpackContext.STATIC_TABLE.length + 1).getHttpField().getName());
    assertEquals("foo", encoder.getHpackContext().get(HpackContext.STATIC_TABLE.length + 0).getHttpField().getName());
    assertMetadataSame(original0, decoded0);
    HttpFields fields1 = new HttpFields();
    fields1.add("123456789012345678901234567890123456788901234567890", "other_value");
    fields1.add("x", "y");
    MetaData original1 = new MetaData(HttpVersion.HTTP_2, fields1);
    BufferUtil.clearToFill(buffer);
    encoder.encode(buffer, original1);
    BufferUtil.flipToFlush(buffer, 0);
    MetaData decoded1 = (MetaData) decoder.decode(buffer);
    assertMetadataSame(original1, decoded1);
    assertEquals(2, encoder.getHpackContext().size());
    assertEquals(2, decoder.getHpackContext().size());
    assertEquals("x", encoder.getHpackContext().get(HpackContext.STATIC_TABLE.length + 0).getHttpField().getName());
    assertEquals("foo", encoder.getHpackContext().get(HpackContext.STATIC_TABLE.length + 1).getHttpField().getName());
}
Also used : MetaData(org.eclipse.jetty.http.MetaData) HttpFields(org.eclipse.jetty.http.HttpFields) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 55 with MetaData

use of org.eclipse.jetty.http.MetaData in project jetty.project by eclipse.

the class MetaDataBuilder method build.

public MetaData build() {
    try {
        HttpFields fields = _fields;
        _fields = new HttpFields(Math.max(10, fields.size() + 5));
        if (_method != null)
            return new MetaData.Request(_method, _scheme, _authority, _path, HttpVersion.HTTP_2, fields, _contentLength);
        if (_status != 0)
            return new MetaData.Response(HttpVersion.HTTP_2, _status, fields, _contentLength);
        return new MetaData(HttpVersion.HTTP_2, fields, _contentLength);
    } finally {
        _status = 0;
        _method = null;
        _scheme = null;
        _authority = null;
        _path = null;
        _size = 0;
        _contentLength = Long.MIN_VALUE;
    }
}
Also used : MetaData(org.eclipse.jetty.http.MetaData) HttpFields(org.eclipse.jetty.http.HttpFields)

Aggregations

MetaData (org.eclipse.jetty.http.MetaData)99 HttpFields (org.eclipse.jetty.http.HttpFields)87 Test (org.junit.Test)79 HeadersFrame (org.eclipse.jetty.http2.frames.HeadersFrame)75 CountDownLatch (java.util.concurrent.CountDownLatch)64 Stream (org.eclipse.jetty.http2.api.Stream)61 Session (org.eclipse.jetty.http2.api.Session)59 ServerSessionListener (org.eclipse.jetty.http2.api.server.ServerSessionListener)57 FuturePromise (org.eclipse.jetty.util.FuturePromise)51 ByteBuffer (java.nio.ByteBuffer)39 HttpServletResponse (javax.servlet.http.HttpServletResponse)36 Promise (org.eclipse.jetty.util.Promise)36 DataFrame (org.eclipse.jetty.http2.frames.DataFrame)35 Callback (org.eclipse.jetty.util.Callback)30 HTTP2Session (org.eclipse.jetty.http2.HTTP2Session)29 ByteBufferPool (org.eclipse.jetty.io.ByteBufferPool)26 IOException (java.io.IOException)24 HashMap (java.util.HashMap)24 HttpServletRequest (javax.servlet.http.HttpServletRequest)24 ServletException (javax.servlet.ServletException)23