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