Search in sources :

Example 56 with HttpField

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

the class HpackTest method encodeDecodeResponseTest.

@Test
public void encodeDecodeResponseTest() {
    HpackEncoder encoder = new HpackEncoder();
    HpackDecoder decoder = new HpackDecoder(4096, 8192);
    ByteBuffer buffer = BufferUtil.allocate(16 * 1024);
    HttpFields fields0 = new HttpFields();
    fields0.add(HttpHeader.CONTENT_TYPE, "text/html");
    fields0.add(HttpHeader.CONTENT_LENGTH, "1024");
    fields0.add(new HttpField(HttpHeader.CONTENT_ENCODING, (String) null));
    fields0.add(ServerJetty);
    fields0.add(XPowerJetty);
    fields0.add(Date);
    fields0.add(HttpHeader.SET_COOKIE, "abcdefghijklmnopqrstuvwxyz");
    fields0.add("custom-key", "custom-value");
    Response original0 = new MetaData.Response(HttpVersion.HTTP_2, 200, fields0);
    BufferUtil.clearToFill(buffer);
    encoder.encode(buffer, original0);
    BufferUtil.flipToFlush(buffer, 0);
    Response decoded0 = (Response) decoder.decode(buffer);
    original0.getFields().put(new HttpField(HttpHeader.CONTENT_ENCODING, ""));
    assertMetadataSame(original0, decoded0);
    // Same again?
    BufferUtil.clearToFill(buffer);
    encoder.encode(buffer, original0);
    BufferUtil.flipToFlush(buffer, 0);
    Response decoded0b = (Response) decoder.decode(buffer);
    assertMetadataSame(original0, decoded0b);
    HttpFields fields1 = new HttpFields();
    fields1.add(HttpHeader.CONTENT_TYPE, "text/plain");
    fields1.add(HttpHeader.CONTENT_LENGTH, "1234");
    fields1.add(HttpHeader.CONTENT_ENCODING, " ");
    fields1.add(ServerJetty);
    fields1.add(XPowerJetty);
    fields1.add(Date);
    fields1.add("Custom-Key", "Other-Value");
    Response original1 = new MetaData.Response(HttpVersion.HTTP_2, 200, fields1);
    // Same again?
    BufferUtil.clearToFill(buffer);
    encoder.encode(buffer, original1);
    BufferUtil.flipToFlush(buffer, 0);
    Response decoded1 = (Response) decoder.decode(buffer);
    assertMetadataSame(original1, decoded1);
    Assert.assertEquals("custom-key", decoded1.getFields().getField("Custom-Key").getName());
}
Also used : Response(org.eclipse.jetty.http.MetaData.Response) HttpField(org.eclipse.jetty.http.HttpField) PreEncodedHttpField(org.eclipse.jetty.http.PreEncodedHttpField) HttpFields(org.eclipse.jetty.http.HttpFields) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 57 with HttpField

use of org.eclipse.jetty.http.HttpField in project jersey by jersey.

the class JettyConnector method processResponseHeaders.

private static void processResponseHeaders(final HttpFields respHeaders, final ClientResponse jerseyResponse) {
    for (final HttpField header : respHeaders) {
        final String headerName = header.getName();
        final MultivaluedMap<String, String> headers = jerseyResponse.getHeaders();
        List<String> list = headers.get(headerName);
        if (list == null) {
            list = new ArrayList<>();
        }
        list.add(header.getValue());
        headers.put(headerName, list);
    }
}
Also used : HttpField(org.eclipse.jetty.http.HttpField)

Aggregations

HttpField (org.eclipse.jetty.http.HttpField)57 Test (org.junit.Test)29 HttpFields (org.eclipse.jetty.http.HttpFields)19 ByteBuffer (java.nio.ByteBuffer)17 MetaData (org.eclipse.jetty.http.MetaData)16 HostPortHttpField (org.eclipse.jetty.http.HostPortHttpField)12 ArrayList (java.util.ArrayList)8 PreEncodedHttpField (org.eclipse.jetty.http.PreEncodedHttpField)7 Entry (org.eclipse.jetty.http2.hpack.HpackContext.Entry)7 ByteBufferPool (org.eclipse.jetty.io.ByteBufferPool)7 MappedByteBufferPool (org.eclipse.jetty.io.MappedByteBufferPool)7 HttpHeader (org.eclipse.jetty.http.HttpHeader)6 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)5 HeaderGenerator (org.eclipse.jetty.http2.generator.HeaderGenerator)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 HpackEncoder (org.eclipse.jetty.http2.hpack.HpackEncoder)4 Parser (org.eclipse.jetty.http2.parser.Parser)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3