Search in sources :

Example 51 with HttpField

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

the class HpackContextTest method testNameInsensitivity.

@Test
public void testNameInsensitivity() {
    HpackContext ctx = new HpackContext(4096);
    assertEquals("content-length", ctx.get("content-length").getHttpField().getName());
    assertEquals("content-length", ctx.get("Content-Length").getHttpField().getName());
    assertTrue(ctx.get("Content-Length").isStatic());
    assertTrue(ctx.get("Content-Type").isStatic());
    ctx.add(new HttpField("Wibble", "Wobble"));
    assertEquals("Wibble", ctx.get("wibble").getHttpField().getName());
    assertEquals("Wibble", ctx.get("Wibble").getHttpField().getName());
}
Also used : HttpField(org.eclipse.jetty.http.HttpField) Test(org.junit.Test)

Example 52 with HttpField

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

the class HpackContextTest method testEvictNames.

@Test
public void testEvictNames() {
    HpackContext ctx = new HpackContext(38 * 2);
    HttpField[] field = { new HttpField("name", "v0"), new HttpField("name", "v1"), new HttpField("name", "v2"), new HttpField("name", "v3"), new HttpField("name", "v4"), new HttpField("name", "v5") };
    Entry[] entry = new Entry[field.length];
    // Add 2 name entries to fill table
    for (int i = 0; i <= 1; i++) entry[i] = ctx.add(field[i]);
    // check there is a name reference and it is the most recent added
    assertEquals(entry[1], ctx.get("name"));
    // Add 1 other entry to table and evict 1
    ctx.add(new HttpField("xxx", "yyy"));
    // check the name reference has been not been evicted
    assertEquals(entry[1], ctx.get("name"));
    // Add 1 other entry to table and evict 1
    ctx.add(new HttpField("foo", "bar"));
    // name is evicted
    assertNull(ctx.get("name"));
}
Also used : Entry(org.eclipse.jetty.http2.hpack.HpackContext.Entry) HttpField(org.eclipse.jetty.http.HttpField) Test(org.junit.Test)

Example 53 with HttpField

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

the class HpackDecoderTest method testDecodeWithArrayOffset.

@Test
public void testDecodeWithArrayOffset() {
    String value = "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==";
    HpackDecoder decoder = new HpackDecoder(4096, 8192);
    String encoded = "8682418cF1E3C2E5F23a6bA0Ab90F4Ff841f0822426173696320515778685a475270626a70766347567549484e6c633246745a513d3d";
    byte[] bytes = TypeUtil.fromHexString(encoded);
    byte[] array = new byte[bytes.length + 1];
    System.arraycopy(bytes, 0, array, 1, bytes.length);
    ByteBuffer buffer = ByteBuffer.wrap(array, 1, bytes.length).slice();
    MetaData.Request request = (MetaData.Request) decoder.decode(buffer);
    assertEquals("GET", request.getMethod());
    assertEquals(HttpScheme.HTTP.asString(), request.getURI().getScheme());
    assertEquals("/", request.getURI().getPath());
    assertEquals("www.example.com", request.getURI().getHost());
    assertEquals(1, request.getFields().size());
    HttpField field = request.iterator().next();
    assertEquals(HttpHeader.AUTHORIZATION, field.getHeader());
    assertEquals(value, field.getValue());
}
Also used : MetaData(org.eclipse.jetty.http.MetaData) HttpField(org.eclipse.jetty.http.HttpField) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 54 with HttpField

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

the class HpackDecoderTest method testDecodeD_3.

@Test
public void testDecodeD_3() {
    HpackDecoder decoder = new HpackDecoder(4096, 8192);
    // First request
    String encoded = "828684410f7777772e6578616d706c652e636f6d";
    ByteBuffer buffer = ByteBuffer.wrap(TypeUtil.fromHexString(encoded));
    MetaData.Request request = (MetaData.Request) decoder.decode(buffer);
    assertEquals("GET", request.getMethod());
    assertEquals(HttpScheme.HTTP.asString(), request.getURI().getScheme());
    assertEquals("/", request.getURI().getPath());
    assertEquals("www.example.com", request.getURI().getHost());
    assertFalse(request.iterator().hasNext());
    // Second request
    encoded = "828684be58086e6f2d6361636865";
    buffer = ByteBuffer.wrap(TypeUtil.fromHexString(encoded));
    request = (MetaData.Request) decoder.decode(buffer);
    assertEquals("GET", request.getMethod());
    assertEquals(HttpScheme.HTTP.asString(), request.getURI().getScheme());
    assertEquals("/", request.getURI().getPath());
    assertEquals("www.example.com", request.getURI().getHost());
    Iterator<HttpField> iterator = request.iterator();
    assertTrue(iterator.hasNext());
    assertEquals(new HttpField("cache-control", "no-cache"), iterator.next());
    assertFalse(iterator.hasNext());
    // Third request
    encoded = "828785bf400a637573746f6d2d6b65790c637573746f6d2d76616c7565";
    buffer = ByteBuffer.wrap(TypeUtil.fromHexString(encoded));
    request = (MetaData.Request) decoder.decode(buffer);
    assertEquals("GET", request.getMethod());
    assertEquals(HttpScheme.HTTPS.asString(), request.getURI().getScheme());
    assertEquals("/index.html", request.getURI().getPath());
    assertEquals("www.example.com", request.getURI().getHost());
    iterator = request.iterator();
    assertTrue(iterator.hasNext());
    assertEquals(new HttpField("custom-key", "custom-value"), iterator.next());
    assertFalse(iterator.hasNext());
}
Also used : MetaData(org.eclipse.jetty.http.MetaData) HttpField(org.eclipse.jetty.http.HttpField) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 55 with HttpField

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

the class HpackDecoderTest method testNghttpx.

@Test
public void testNghttpx() {
    // Response encoded by nghttpx
    String encoded = "886196C361Be940b6a65B6850400B8A00571972e080a62D1Bf5f87497cA589D34d1f9a0f0d0234327690Aa69D29aFcA954D3A5358980Ae112e0f7c880aE152A9A74a6bF3";
    ByteBuffer buffer = ByteBuffer.wrap(TypeUtil.fromHexString(encoded));
    HpackDecoder decoder = new HpackDecoder(4096, 8192);
    MetaData.Response response = (MetaData.Response) decoder.decode(buffer);
    assertThat(response.getStatus(), is(200));
    assertThat(response.getFields().size(), is(6));
    assertTrue(response.getFields().contains(new HttpField(HttpHeader.DATE, "Fri, 15 Jul 2016 02:36:20 GMT")));
    assertTrue(response.getFields().contains(new HttpField(HttpHeader.CONTENT_TYPE, "text/html")));
    assertTrue(response.getFields().contains(new HttpField(HttpHeader.CONTENT_ENCODING, "")));
    assertTrue(response.getFields().contains(new HttpField(HttpHeader.CONTENT_LENGTH, "42")));
    assertTrue(response.getFields().contains(new HttpField(HttpHeader.SERVER, "nghttpx nghttp2/1.12.0")));
    assertTrue(response.getFields().contains(new HttpField(HttpHeader.VIA, "1.1 nghttpx")));
}
Also used : MetaData(org.eclipse.jetty.http.MetaData) HttpField(org.eclipse.jetty.http.HttpField) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

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