use of org.eclipse.jetty.http.MetaData in project jetty.project by eclipse.
the class HpackEncoderTest method testNeverIndexSetCookie.
@Test
public void testNeverIndexSetCookie() {
HpackEncoder encoder = new HpackEncoder(38 * 5);
ByteBuffer buffer = BufferUtil.allocate(4096);
HttpFields fields = new HttpFields();
fields.put("set-cookie", "some cookie value");
// encode
BufferUtil.clearToFill(buffer);
encoder.encode(buffer, new MetaData(HttpVersion.HTTP_2, fields));
BufferUtil.flipToFlush(buffer, 0);
// something was encoded!
assertThat(buffer.remaining(), Matchers.greaterThan(0));
// empty dynamic table
Assert.assertEquals(0, encoder.getHpackContext().size());
// encode again
BufferUtil.clearToFill(buffer);
encoder.encode(buffer, new MetaData(HttpVersion.HTTP_2, fields));
BufferUtil.flipToFlush(buffer, 0);
// something was encoded!
assertThat(buffer.remaining(), Matchers.greaterThan(0));
// empty dynamic table
Assert.assertEquals(0, encoder.getHpackContext().size());
}
use of org.eclipse.jetty.http.MetaData in project jetty.project by eclipse.
the class HpackPerfTest method encodeStories.
private void encodeStories(ByteBuffer buffer, Map<String, Object>[] stories, String type) throws Exception {
for (Map<String, Object> story : stories) {
if (type.equals(story.get("context"))) {
HpackEncoder encoder = new HpackEncoder(_maxDynamicTableSize, _maxDynamicTableSize);
// System.err.println(story);
Object[] cases = (Object[]) story.get("cases");
for (Object c : cases) {
// System.err.println(" "+c);
Object[] headers = (Object[]) ((Map<String, Object>) c).get("headers");
// System.err.println(" "+headers);
HttpFields fields = new HttpFields();
for (Object header : headers) {
Map<String, String> h = (Map<String, String>) header;
Map.Entry<String, String> e = h.entrySet().iterator().next();
fields.add(e.getKey(), e.getValue());
_unencodedSize += e.getKey().length() + e.getValue().length();
}
BufferUtil.clearToFill(buffer);
encoder.encode(buffer, new MetaData(HttpVersion.HTTP_2, fields));
BufferUtil.flipToFlush(buffer, 0);
_encodedSize += buffer.remaining();
}
}
}
}
use of org.eclipse.jetty.http.MetaData in project jetty.project by eclipse.
the class HpackTest method encodeDecodeTooLargeTest.
@Test
public void encodeDecodeTooLargeTest() {
HpackEncoder encoder = new HpackEncoder();
HpackDecoder decoder = new HpackDecoder(4096, 164);
ByteBuffer buffer = BufferUtil.allocate(16 * 1024);
HttpFields fields0 = new HttpFields();
fields0.add("1234567890", "1234567890123456789012345678901234567890");
fields0.add("Cookie", "abcdeffhijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQR");
MetaData original0 = new MetaData(HttpVersion.HTTP_2, fields0);
BufferUtil.clearToFill(buffer);
encoder.encode(buffer, original0);
BufferUtil.flipToFlush(buffer, 0);
MetaData decoded0 = (MetaData) decoder.decode(buffer);
assertMetadataSame(original0, decoded0);
HttpFields fields1 = new HttpFields();
fields1.add("1234567890", "1234567890123456789012345678901234567890");
fields1.add("Cookie", "abcdeffhijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQR");
fields1.add("x", "y");
MetaData original1 = new MetaData(HttpVersion.HTTP_2, fields1);
BufferUtil.clearToFill(buffer);
encoder.encode(buffer, original1);
BufferUtil.flipToFlush(buffer, 0);
try {
decoder.decode(buffer);
Assert.fail();
} catch (BadMessageException e) {
assertEquals(HttpStatus.REQUEST_HEADER_FIELDS_TOO_LARGE_431, e.getCode());
}
}
use of org.eclipse.jetty.http.MetaData in project jetty.project by eclipse.
the class HpackTest method evictReferencedFieldTest.
@Test
public void evictReferencedFieldTest() {
HpackEncoder encoder = new HpackEncoder(200, 200);
HpackDecoder decoder = new HpackDecoder(200, 1024);
ByteBuffer buffer = BufferUtil.allocate(16 * 1024);
HttpFields fields0 = new HttpFields();
fields0.add("123456789012345678901234567890123456788901234567890", "value");
fields0.add("foo", "abcdeffhijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQR");
MetaData original0 = new MetaData(HttpVersion.HTTP_2, fields0);
BufferUtil.clearToFill(buffer);
encoder.encode(buffer, original0);
BufferUtil.flipToFlush(buffer, 0);
MetaData decoded0 = (MetaData) decoder.decode(buffer);
assertEquals(2, encoder.getHpackContext().size());
assertEquals(2, decoder.getHpackContext().size());
assertEquals("123456789012345678901234567890123456788901234567890", encoder.getHpackContext().get(HpackContext.STATIC_TABLE.length + 1).getHttpField().getName());
assertEquals("foo", encoder.getHpackContext().get(HpackContext.STATIC_TABLE.length + 0).getHttpField().getName());
assertMetadataSame(original0, decoded0);
HttpFields fields1 = new HttpFields();
fields1.add("123456789012345678901234567890123456788901234567890", "other_value");
fields1.add("x", "y");
MetaData original1 = new MetaData(HttpVersion.HTTP_2, fields1);
BufferUtil.clearToFill(buffer);
encoder.encode(buffer, original1);
BufferUtil.flipToFlush(buffer, 0);
MetaData decoded1 = (MetaData) decoder.decode(buffer);
assertMetadataSame(original1, decoded1);
assertEquals(2, encoder.getHpackContext().size());
assertEquals(2, decoder.getHpackContext().size());
assertEquals("x", encoder.getHpackContext().get(HpackContext.STATIC_TABLE.length + 0).getHttpField().getName());
assertEquals("foo", encoder.getHpackContext().get(HpackContext.STATIC_TABLE.length + 1).getHttpField().getName());
}
use of org.eclipse.jetty.http.MetaData in project jetty.project by eclipse.
the class MetaDataBuilder method build.
public MetaData build() {
try {
HttpFields fields = _fields;
_fields = new HttpFields(Math.max(10, fields.size() + 5));
if (_method != null)
return new MetaData.Request(_method, _scheme, _authority, _path, HttpVersion.HTTP_2, fields, _contentLength);
if (_status != 0)
return new MetaData.Response(HttpVersion.HTTP_2, _status, fields, _contentLength);
return new MetaData(HttpVersion.HTTP_2, fields, _contentLength);
} finally {
_status = 0;
_method = null;
_scheme = null;
_authority = null;
_path = null;
_size = 0;
_contentLength = Long.MIN_VALUE;
}
}
Aggregations