Search in sources :

Example 16 with MimeHeaders

use of org.apache.tomcat.util.http.MimeHeaders in project tomcat by apache.

the class Http2TestBase method buildGetRequest.

protected void buildGetRequest(byte[] frameHeader, ByteBuffer headersPayload, byte[] padding, List<Header> headers, int streamId) {
    if (padding != null) {
        headersPayload.put((byte) (0xFF & padding.length));
    }
    MimeHeaders mimeHeaders = new MimeHeaders();
    for (Header header : headers) {
        mimeHeaders.addValue(header.getName()).setString(header.getValue());
    }
    hpackEncoder.encode(mimeHeaders, headersPayload);
    if (padding != null) {
        headersPayload.put(padding);
    }
    headersPayload.flip();
    ByteUtil.setThreeBytes(frameHeader, 0, headersPayload.limit());
    frameHeader[3] = FrameType.HEADERS.getIdByte();
    // Flags. end of headers (0x04). end of stream (0x01)
    frameHeader[4] = 0x05;
    if (padding != null) {
        frameHeader[4] += 0x08;
    }
    // Stream id
    ByteUtil.set31Bits(frameHeader, 5, streamId);
}
Also used : MimeHeaders(org.apache.tomcat.util.http.MimeHeaders)

Example 17 with MimeHeaders

use of org.apache.tomcat.util.http.MimeHeaders in project tomcat by apache.

the class TestHpack method doTestHeaderValueBug60451.

private void doTestHeaderValueBug60451(String filename) throws HpackException {
    String headerName = "Content-Disposition";
    String headerValue = "attachment;filename=\"" + filename + "\"";
    MimeHeaders headers = new MimeHeaders();
    headers.setValue(headerName).setString(headerValue);
    ByteBuffer output = ByteBuffer.allocate(512);
    HpackEncoder encoder = new HpackEncoder();
    encoder.encode(headers, output);
    output.flip();
    MimeHeaders headers2 = new MimeHeaders();
    HpackDecoder decoder = new HpackDecoder();
    decoder.setHeaderEmitter(new HeadersListener(headers2));
    decoder.decode(output);
    Assert.assertEquals(headerValue, headers2.getHeader(headerName));
}
Also used : MimeHeaders(org.apache.tomcat.util.http.MimeHeaders) ByteBuffer(java.nio.ByteBuffer)

Example 18 with MimeHeaders

use of org.apache.tomcat.util.http.MimeHeaders in project tomcat by apache.

the class TestHpack method testDecode.

@Test
public void testDecode() throws Exception {
    MimeHeaders headers = new MimeHeaders();
    headers.setValue("header1").setString("value1");
    headers.setValue(":status").setString("200");
    headers.setValue("header2").setString("value2");
    ByteBuffer output = ByteBuffer.allocate(512);
    HpackEncoder encoder = new HpackEncoder();
    encoder.encode(headers, output);
    output.flip();
    MimeHeaders headers2 = new MimeHeaders();
    HpackDecoder decoder = new HpackDecoder();
    decoder.setHeaderEmitter(new HeadersListener(headers2));
    decoder.decode(output);
    // Redo (table is supposed to be updated)
    output.clear();
    encoder.encode(headers, output);
    output.flip();
    headers2.recycle();
    Assert.assertEquals(3, output.remaining());
    // Check that the decoder is using the table right
    decoder.decode(output);
    Assert.assertEquals("value2", headers2.getHeader("header2"));
}
Also used : MimeHeaders(org.apache.tomcat.util.http.MimeHeaders) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

MimeHeaders (org.apache.tomcat.util.http.MimeHeaders)18 MessageBytes (org.apache.tomcat.util.buf.MessageBytes)6 ByteBuffer (java.nio.ByteBuffer)3 ByteChunk (org.apache.tomcat.util.buf.ByteChunk)3 Test (org.junit.Test)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 Locale (java.util.Locale)1 Pattern (java.util.regex.Pattern)1 Cookie (javax.servlet.http.Cookie)1 BufferedInputFilter (org.apache.coyote.http11.filters.BufferedInputFilter)1 ChunkedInputFilter (org.apache.coyote.http11.filters.ChunkedInputFilter)1 ChunkedOutputFilter (org.apache.coyote.http11.filters.ChunkedOutputFilter)1 GzipOutputFilter (org.apache.coyote.http11.filters.GzipOutputFilter)1 IdentityInputFilter (org.apache.coyote.http11.filters.IdentityInputFilter)1 IdentityOutputFilter (org.apache.coyote.http11.filters.IdentityOutputFilter)1 SavedRequestInputFilter (org.apache.coyote.http11.filters.SavedRequestInputFilter)1 VoidInputFilter (org.apache.coyote.http11.filters.VoidInputFilter)1