Search in sources :

Example 86 with HttpFields

use of org.eclipse.jetty.http.HttpFields 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 87 with HttpFields

use of org.eclipse.jetty.http.HttpFields 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 88 with HttpFields

use of org.eclipse.jetty.http.HttpFields 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 89 with HttpFields

use of org.eclipse.jetty.http.HttpFields 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 90 with HttpFields

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

the class ThreadLimitHandler method getForwarded.

private String getForwarded(Request request) {
    // Get the right most Forwarded for value.
    // This is the value from the closest proxy and the only one that
    // can be trusted.
    RFC7239 rfc7239 = new RFC7239();
    HttpFields httpFields = request.getHttpFields();
    for (HttpField field : httpFields) if (_forwardedHeader.equalsIgnoreCase(field.getName()))
        rfc7239.addValue(field.getValue());
    if (rfc7239.getFor() != null)
        return new HostPortHttpField(rfc7239.getFor()).getHost();
    return null;
}
Also used : HostPortHttpField(org.eclipse.jetty.http.HostPortHttpField) HttpField(org.eclipse.jetty.http.HttpField) HttpFields(org.eclipse.jetty.http.HttpFields) HostPortHttpField(org.eclipse.jetty.http.HostPortHttpField)

Aggregations

HttpFields (org.eclipse.jetty.http.HttpFields)172 Test (org.junit.Test)142 MetaData (org.eclipse.jetty.http.MetaData)117 HeadersFrame (org.eclipse.jetty.http2.frames.HeadersFrame)105 CountDownLatch (java.util.concurrent.CountDownLatch)96 Stream (org.eclipse.jetty.http2.api.Stream)93 Session (org.eclipse.jetty.http2.api.Session)89 ServerSessionListener (org.eclipse.jetty.http2.api.server.ServerSessionListener)79 FuturePromise (org.eclipse.jetty.util.FuturePromise)69 HttpServletResponse (javax.servlet.http.HttpServletResponse)59 DataFrame (org.eclipse.jetty.http2.frames.DataFrame)55 Callback (org.eclipse.jetty.util.Callback)53 ByteBuffer (java.nio.ByteBuffer)52 Promise (org.eclipse.jetty.util.Promise)49 HttpServletRequest (javax.servlet.http.HttpServletRequest)46 IOException (java.io.IOException)42 ServletException (javax.servlet.ServletException)39 HTTP2Session (org.eclipse.jetty.http2.HTTP2Session)37 HttpServlet (javax.servlet.http.HttpServlet)33 HashMap (java.util.HashMap)32