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;
}
}
use of org.eclipse.jetty.http.MetaData in project jetty.project by eclipse.
the class ContinuationBodyParser method onHeaders.
private void onHeaders() {
ByteBuffer headerBlock = headerBlockFragments.complete();
MetaData metaData = headerBlockParser.parse(headerBlock, headerBlock.remaining());
HeadersFrame frame = new HeadersFrame(getStreamId(), metaData, headerBlockFragments.getPriorityFrame(), headerBlockFragments.isEndStream());
notifyHeaders(frame);
}
use of org.eclipse.jetty.http.MetaData in project jetty.project by eclipse.
the class HeaderBlockParser method parse.
public MetaData parse(ByteBuffer buffer, int blockLength) {
// We must wait for the all the bytes of the header block to arrive.
// If they are not all available, accumulate them.
// When all are available, decode them.
int accumulated = blockBuffer == null ? 0 : blockBuffer.position();
int remaining = blockLength - accumulated;
if (buffer.remaining() < remaining) {
if (blockBuffer == null) {
blockBuffer = byteBufferPool.acquire(blockLength, false);
BufferUtil.clearToFill(blockBuffer);
}
blockBuffer.put(buffer);
return null;
} else {
int limit = buffer.limit();
buffer.limit(buffer.position() + remaining);
ByteBuffer toDecode;
if (blockBuffer != null) {
blockBuffer.put(buffer);
BufferUtil.flipToFlush(blockBuffer, 0);
toDecode = blockBuffer;
} else {
toDecode = buffer;
}
MetaData result = hpackDecoder.decode(toDecode);
buffer.limit(limit);
if (blockBuffer != null) {
byteBufferPool.release(blockBuffer);
blockBuffer = null;
}
return result;
}
}
Aggregations