Search in sources :

Example 11 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 12 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 13 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)

Example 14 with MetaData

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

the class ContinuationBodyParser method onHeaders.

private void onHeaders() {
    ByteBuffer headerBlock = headerBlockFragments.complete();
    MetaData metaData = headerBlockParser.parse(headerBlock, headerBlock.remaining());
    HeadersFrame frame = new HeadersFrame(getStreamId(), metaData, headerBlockFragments.getPriorityFrame(), headerBlockFragments.isEndStream());
    notifyHeaders(frame);
}
Also used : MetaData(org.eclipse.jetty.http.MetaData) ByteBuffer(java.nio.ByteBuffer) HeadersFrame(org.eclipse.jetty.http2.frames.HeadersFrame)

Example 15 with MetaData

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

the class HeaderBlockParser method parse.

public MetaData parse(ByteBuffer buffer, int blockLength) {
    // We must wait for the all the bytes of the header block to arrive.
    // If they are not all available, accumulate them.
    // When all are available, decode them.
    int accumulated = blockBuffer == null ? 0 : blockBuffer.position();
    int remaining = blockLength - accumulated;
    if (buffer.remaining() < remaining) {
        if (blockBuffer == null) {
            blockBuffer = byteBufferPool.acquire(blockLength, false);
            BufferUtil.clearToFill(blockBuffer);
        }
        blockBuffer.put(buffer);
        return null;
    } else {
        int limit = buffer.limit();
        buffer.limit(buffer.position() + remaining);
        ByteBuffer toDecode;
        if (blockBuffer != null) {
            blockBuffer.put(buffer);
            BufferUtil.flipToFlush(blockBuffer, 0);
            toDecode = blockBuffer;
        } else {
            toDecode = buffer;
        }
        MetaData result = hpackDecoder.decode(toDecode);
        buffer.limit(limit);
        if (blockBuffer != null) {
            byteBufferPool.release(blockBuffer);
            blockBuffer = null;
        }
        return result;
    }
}
Also used : MetaData(org.eclipse.jetty.http.MetaData) ByteBuffer(java.nio.ByteBuffer)

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