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());
}
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"));
}
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());
}
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());
}
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")));
}
Aggregations