Improvements & bug fixes from testing
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
parent
22e513a272
commit
a95fe3bfb8
|
@ -54,9 +54,13 @@ public class PreEncodedHttpField extends HttpField
|
|||
});
|
||||
|
||||
LOG.debug("HttpField encoders loaded: {}", encoders);
|
||||
int size = encoders.size();
|
||||
|
||||
__encoders = new HttpFieldPreEncoder[size == 0 ? 1 : size];
|
||||
int size = 1;
|
||||
for (HttpFieldPreEncoder e : encoders)
|
||||
{
|
||||
size = Math.max(size, index(e.getHttpVersion()) + 1);
|
||||
}
|
||||
__encoders = new HttpFieldPreEncoder[size];
|
||||
for (HttpFieldPreEncoder e : encoders)
|
||||
{
|
||||
int i = index(e.getHttpVersion());
|
||||
|
@ -82,6 +86,9 @@ public class PreEncodedHttpField extends HttpField
|
|||
case HTTP_2:
|
||||
return 1;
|
||||
|
||||
case HTTP_3:
|
||||
return 2;
|
||||
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
@ -94,7 +101,8 @@ public class PreEncodedHttpField extends HttpField
|
|||
super(header, name, value);
|
||||
for (int i = 0; i < __encoders.length; i++)
|
||||
{
|
||||
_encodedField[i] = __encoders[i].getEncodedField(header, name, value);
|
||||
if (__encoders[i] != null)
|
||||
_encodedField[i] = __encoders[i].getEncodedField(header, name, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.eclipse.jetty.http3.qpack.internal.table.DynamicTable;
|
|||
import org.eclipse.jetty.http3.qpack.internal.table.Entry;
|
||||
import org.eclipse.jetty.http3.qpack.internal.table.StaticTable;
|
||||
import org.eclipse.jetty.http3.qpack.internal.util.NBitIntegerParser;
|
||||
import org.eclipse.jetty.util.BufferUtil;
|
||||
import org.eclipse.jetty.util.component.Dumpable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -66,7 +67,7 @@ public class QpackDecoder implements Dumpable
|
|||
|
||||
public interface Handler
|
||||
{
|
||||
void onHttpFields(int streamId, MetaData metadata);
|
||||
void onMetaData(int streamId, MetaData metadata);
|
||||
|
||||
void onInstruction(Instruction instruction) throws QpackException;
|
||||
}
|
||||
|
@ -74,7 +75,7 @@ public class QpackDecoder implements Dumpable
|
|||
public void decode(int streamId, ByteBuffer buffer) throws QpackException
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug(String.format("CtxTbl[%x] decoding %d octets", _context.hashCode(), buffer.remaining()));
|
||||
LOG.debug("Decoding: streamId={}, buffer={}", streamId, BufferUtil.toDetailString(buffer));
|
||||
|
||||
// If the buffer is big, don't even think about decoding it
|
||||
if (buffer.remaining() > _maxHeaderSize)
|
||||
|
@ -104,11 +105,17 @@ public class QpackDecoder implements Dumpable
|
|||
// Decode it straight away if we can, otherwise add it to the list of EncodedFieldSections.
|
||||
if (requiredInsertCount <= insertCount)
|
||||
{
|
||||
_handler.onHttpFields(streamId, encodedFieldSection.decode(_context, _maxHeaderSize));
|
||||
MetaData metaData = encodedFieldSection.decode(_context, _maxHeaderSize);
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("Decoded: streamId={}, metadata={}", streamId, metaData);
|
||||
|
||||
_handler.onMetaData(streamId, metaData);
|
||||
_handler.onInstruction(new SectionAcknowledgmentInstruction(streamId));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("Deferred Decoding: streamId={}, encodedFieldSection={}", streamId, encodedFieldSection);
|
||||
_encodedFieldSections.add(encodedFieldSection);
|
||||
}
|
||||
}
|
||||
|
@ -125,8 +132,13 @@ public class QpackDecoder implements Dumpable
|
|||
{
|
||||
if (encodedFieldSection.getRequiredInsertCount() <= insertCount)
|
||||
{
|
||||
_handler.onHttpFields(encodedFieldSection.getStreamId(), encodedFieldSection.decode(_context, _maxHeaderSize));
|
||||
_handler.onInstruction(new SectionAcknowledgmentInstruction(encodedFieldSection.getStreamId()));
|
||||
int streamId = encodedFieldSection.getStreamId();
|
||||
MetaData metaData = encodedFieldSection.decode(_context, _maxHeaderSize);
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("Decoded: streamId={}, metadata={}", streamId, metaData);
|
||||
|
||||
_handler.onMetaData(streamId, metaData);
|
||||
_handler.onInstruction(new SectionAcknowledgmentInstruction(streamId));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -138,10 +150,14 @@ public class QpackDecoder implements Dumpable
|
|||
|
||||
void insert(int index) throws QpackException
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("Duplicate: index={}", index);
|
||||
|
||||
DynamicTable dynamicTable = _context.getDynamicTable();
|
||||
Entry entry = dynamicTable.get(index);
|
||||
Entry referencedEntry = dynamicTable.get(index);
|
||||
|
||||
// Add the new Entry to the DynamicTable.
|
||||
Entry entry = new Entry(referencedEntry.getHttpField());
|
||||
dynamicTable.add(entry);
|
||||
_handler.onInstruction(new InsertCountIncrementInstruction(1));
|
||||
checkEncodedFieldSections();
|
||||
|
@ -149,6 +165,9 @@ public class QpackDecoder implements Dumpable
|
|||
|
||||
void insert(int nameIndex, boolean isDynamicTableIndex, String value) throws QpackException
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("Insert Name Reference: nameIndex={}, dynamic={}, value={}", nameIndex, isDynamicTableIndex, value);
|
||||
|
||||
StaticTable staticTable = QpackContext.getStaticTable();
|
||||
DynamicTable dynamicTable = _context.getDynamicTable();
|
||||
Entry referencedEntry = isDynamicTableIndex ? dynamicTable.get(nameIndex) : staticTable.get(nameIndex);
|
||||
|
@ -162,6 +181,9 @@ public class QpackDecoder implements Dumpable
|
|||
|
||||
void insert(String name, String value) throws QpackException
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("Insert Literal Entry: name={}, value={}", name, value);
|
||||
|
||||
Entry entry = new Entry(new HttpField(name, value));
|
||||
|
||||
// Add the new Entry to the DynamicTable.
|
||||
|
|
|
@ -249,10 +249,10 @@ public class MetaDataBuilder
|
|||
else
|
||||
return new MetaData.Request(
|
||||
_method,
|
||||
_scheme == null ? HttpScheme.HTTP.asString() : _scheme.asString(),
|
||||
_scheme.asString(),
|
||||
_authority,
|
||||
_path,
|
||||
HttpVersion.HTTP_2,
|
||||
HttpVersion.HTTP_3,
|
||||
fields,
|
||||
_contentLength);
|
||||
}
|
||||
|
@ -260,10 +260,10 @@ public class MetaDataBuilder
|
|||
{
|
||||
if (_status == null)
|
||||
throw new QpackException.StreamException("No Status");
|
||||
return new MetaData.Response(HttpVersion.HTTP_2, _status, fields, _contentLength);
|
||||
return new MetaData.Response(HttpVersion.HTTP_3, _status, fields, _contentLength);
|
||||
}
|
||||
|
||||
return new MetaData(HttpVersion.HTTP_2, fields, _contentLength);
|
||||
return new MetaData(HttpVersion.HTTP_3, fields, _contentLength);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
|
|
@ -109,7 +109,7 @@ public class EncodedFieldSection
|
|||
_stringParser.setPrefix(8);
|
||||
String value = _stringParser.decode(buffer);
|
||||
if (value == null)
|
||||
throw new QpackException.CompressionException("Value");
|
||||
throw new QpackException.CompressionException("Incomplete Value");
|
||||
|
||||
return new IndexedNameField(allowEncoding, dynamicTable, nameIndex, value);
|
||||
}
|
||||
|
|
|
@ -144,8 +144,8 @@ public class DynamicTable implements Iterable<Entry>, Dumpable
|
|||
|
||||
Entry firstEntry = _entries.get(0);
|
||||
int index = absoluteIndex - firstEntry.getIndex();
|
||||
if (index >= _entries.size())
|
||||
throw new IllegalArgumentException("Invalid Index");
|
||||
if (index < 0 || index >= _entries.size())
|
||||
throw new IllegalArgumentException("Invalid Index " + index);
|
||||
|
||||
return _entries.get(index);
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ public class TestDecoderHandler implements QpackDecoder.Handler
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onHttpFields(int streamId, MetaData metadata)
|
||||
public void onMetaData(int streamId, MetaData metadata)
|
||||
{
|
||||
_metadataList.add(metadata);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue