use of org.eclipse.jetty.http.MetaData.Response in project jetty.project by eclipse.
the class HpackTest method encodeDecodeResponseTest.
@Test
public void encodeDecodeResponseTest() {
HpackEncoder encoder = new HpackEncoder();
HpackDecoder decoder = new HpackDecoder(4096, 8192);
ByteBuffer buffer = BufferUtil.allocate(16 * 1024);
HttpFields fields0 = new HttpFields();
fields0.add(HttpHeader.CONTENT_TYPE, "text/html");
fields0.add(HttpHeader.CONTENT_LENGTH, "1024");
fields0.add(new HttpField(HttpHeader.CONTENT_ENCODING, (String) null));
fields0.add(ServerJetty);
fields0.add(XPowerJetty);
fields0.add(Date);
fields0.add(HttpHeader.SET_COOKIE, "abcdefghijklmnopqrstuvwxyz");
fields0.add("custom-key", "custom-value");
Response original0 = new MetaData.Response(HttpVersion.HTTP_2, 200, fields0);
BufferUtil.clearToFill(buffer);
encoder.encode(buffer, original0);
BufferUtil.flipToFlush(buffer, 0);
Response decoded0 = (Response) decoder.decode(buffer);
original0.getFields().put(new HttpField(HttpHeader.CONTENT_ENCODING, ""));
assertMetadataSame(original0, decoded0);
// Same again?
BufferUtil.clearToFill(buffer);
encoder.encode(buffer, original0);
BufferUtil.flipToFlush(buffer, 0);
Response decoded0b = (Response) decoder.decode(buffer);
assertMetadataSame(original0, decoded0b);
HttpFields fields1 = new HttpFields();
fields1.add(HttpHeader.CONTENT_TYPE, "text/plain");
fields1.add(HttpHeader.CONTENT_LENGTH, "1234");
fields1.add(HttpHeader.CONTENT_ENCODING, " ");
fields1.add(ServerJetty);
fields1.add(XPowerJetty);
fields1.add(Date);
fields1.add("Custom-Key", "Other-Value");
Response original1 = new MetaData.Response(HttpVersion.HTTP_2, 200, fields1);
// Same again?
BufferUtil.clearToFill(buffer);
encoder.encode(buffer, original1);
BufferUtil.flipToFlush(buffer, 0);
Response decoded1 = (Response) decoder.decode(buffer);
assertMetadataSame(original1, decoded1);
Assert.assertEquals("custom-key", decoded1.getFields().getField("Custom-Key").getName());
}
Aggregations