use of org.eclipse.jetty.http.HttpField in project jetty.project by eclipse.
the class HpackContextTest method testEvictOne.
@Test
public void testEvictOne() {
HpackContext ctx = new HpackContext(38);
HttpField field0 = new HttpField("foo", "bar");
assertEquals(field0, ctx.add(field0).getHttpField());
assertEquals(field0, ctx.get("foo").getHttpField());
HttpField field1 = new HttpField("xxx", "yyy");
assertEquals(field1, ctx.add(field1).getHttpField());
assertNull(ctx.get(field0));
assertNull(ctx.get("foo"));
assertEquals(field1, ctx.get(field1).getHttpField());
assertEquals(field1, ctx.get("xxx").getHttpField());
}
use of org.eclipse.jetty.http.HttpField in project jetty.project by eclipse.
the class HpackContextTest method testGetAddStatic.
@Test
public void testGetAddStatic() {
HpackContext ctx = new HpackContext(4096);
// Look for the field. Should find static version.
HttpField methodGet = new HttpField(":method", "GET");
assertEquals(methodGet, ctx.get(methodGet).getHttpField());
assertTrue(ctx.get(methodGet).isStatic());
// Add static version to dynamic table
Entry e0 = ctx.add(ctx.get(methodGet).getHttpField());
// Look again and should see dynamic version
assertEquals(methodGet, ctx.get(methodGet).getHttpField());
assertFalse(methodGet == ctx.get(methodGet).getHttpField());
assertFalse(ctx.get(methodGet).isStatic());
// Duplicates allows
Entry e1 = ctx.add(ctx.get(methodGet).getHttpField());
// Look again and should see dynamic version
assertEquals(methodGet, ctx.get(methodGet).getHttpField());
assertFalse(methodGet == ctx.get(methodGet).getHttpField());
assertFalse(ctx.get(methodGet).isStatic());
assertFalse(e0 == e1);
}
use of org.eclipse.jetty.http.HttpField in project jetty.project by eclipse.
the class HpackContextTest method testEmptyAdd.
@Test
public void testEmptyAdd() {
HpackContext ctx = new HpackContext(0);
HttpField field = new HttpField("foo", "bar");
Assert.assertNull(ctx.add(field));
}
use of org.eclipse.jetty.http.HttpField in project jetty.project by eclipse.
the class HpackDecoderTest method testDecodeD_4.
@Test
public void testDecodeD_4() {
HpackDecoder decoder = new HpackDecoder(4096, 8192);
// First request
String encoded = "828684418cf1e3c2e5f23a6ba0ab90f4ff";
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 = "828684be5886a8eb10649cbf";
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());
}
use of org.eclipse.jetty.http.HttpField in project jetty.project by eclipse.
the class Response method putHeaders.
public void putHeaders(HttpContent content, long contentLength, boolean etag) {
HttpField lm = content.getLastModified();
if (lm != null)
_fields.put(lm);
if (contentLength == 0) {
_fields.put(content.getContentLength());
_contentLength = content.getContentLengthValue();
} else if (contentLength > 0) {
_fields.putLongField(HttpHeader.CONTENT_LENGTH, contentLength);
_contentLength = contentLength;
}
HttpField ct = content.getContentType();
if (ct != null) {
_fields.put(ct);
_contentType = ct.getValue();
_characterEncoding = content.getCharacterEncoding();
_mimeType = content.getMimeType();
}
HttpField ce = content.getContentEncoding();
if (ce != null)
_fields.put(ce);
if (etag) {
HttpField et = content.getETag();
if (et != null)
_fields.put(et);
}
}
Aggregations