Search in sources :

Example 11 with HttpField

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());
}
Also used : HttpField(org.eclipse.jetty.http.HttpField) Test(org.junit.Test)

Example 12 with HttpField

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);
}
Also used : Entry(org.eclipse.jetty.http2.hpack.HpackContext.Entry) HttpField(org.eclipse.jetty.http.HttpField) Test(org.junit.Test)

Example 13 with HttpField

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));
}
Also used : HttpField(org.eclipse.jetty.http.HttpField) Test(org.junit.Test)

Example 14 with HttpField

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());
}
Also used : MetaData(org.eclipse.jetty.http.MetaData) HttpField(org.eclipse.jetty.http.HttpField) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 15 with HttpField

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);
    }
}
Also used : HttpField(org.eclipse.jetty.http.HttpField) PreEncodedHttpField(org.eclipse.jetty.http.PreEncodedHttpField)

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