{
// Unknown field entry, so we will have to send literally.
final boolean indexed;
// But do we know it's name?
HttpHeader header = field.getHeader();
// Select encoding strategy
if (header==null)
{
// Select encoding strategy for unknown header names
Entry name = _context.get(field.getName());
if (field instanceof PreEncodedHttpField)
{
int i=buffer.position();
((PreEncodedHttpField)field).putTo(buffer,HttpVersion.HTTP_2);
byte b=buffer.get(i);
indexed=b<0||b>=0x40;
if (_debug)
encoding=indexed?"PreEncodedIdx":"PreEncoded";
}
// has the custom header name been seen before?
else if (name==null)
{
// unknown name and value, so let's index this just in case it is
// the first time we have seen a custom name or a custom field.
// unless the name is changing, this is worthwhile
indexed=true;
encodeName(buffer,(byte)0x40,6,field.getName(),null);
encodeValue(buffer,true,field.getValue());
if (_debug)
encoding="LitHuffNHuffVIdx";
}
else
{
// known custom name, but unknown value.
// This is probably a custom field with changing value, so don't index.
indexed=false;
encodeName(buffer,(byte)0x00,4,field.getName(),null);
encodeValue(buffer,true,field.getValue());
if (_debug)
encoding="LitHuffNHuffV!Idx";
}
}
else
{
// Select encoding strategy for known header names
Entry name = _context.get(header);
if (field instanceof PreEncodedHttpField)
{
// Preencoded field
int i=buffer.position();
((PreEncodedHttpField)field).putTo(buffer,HttpVersion.HTTP_2);
byte b=buffer.get(i);
indexed=b<0||b>=0x40;
if (_debug)
encoding=indexed?"PreEncodedIdx":"PreEncoded";
}
else if (__DO_NOT_INDEX.contains(header))
{
// Non indexed field
indexed=false;
boolean never_index=__NEVER_INDEX.contains(header);
boolean huffman=!__DO_NOT_HUFFMAN.contains(header);
encodeName(buffer,never_index?(byte)0x10:(byte)0x00,4,header.asString(),name);
encodeValue(buffer,huffman,field.getValue());
if (_debug)
encoding="Lit"+
((name==null)?"HuffN":("IdxN"+(name.isStatic()?"S":"")+(1+NBitInteger.octectsNeeded(4,_context.index(name)))))+
(huffman?"HuffV":"LitV")+
(indexed?"Idx":(never_index?"!!Idx":"!Idx"));
}
else if (header==HttpHeader.CONTENT_LENGTH && field.getValue().length()>1)
{
// Non indexed content length for 2 digits or more
indexed=false;
encodeName(buffer,(byte)0x00,4,header.asString(),name);
encodeValue(buffer,true,field.getValue());
if (_debug)
encoding="LitIdxNS"+(1+NBitInteger.octectsNeeded(4,_context.index(name)))+"HuffV!Idx";
}
else
{
// indexed
indexed=true;
boolean huffman=!__DO_NOT_HUFFMAN.contains(header);
encodeName(buffer,(byte)0x40,6,header.asString(),name);
encodeValue(buffer,huffman,field.getValue());
if (_debug)
encoding=((name==null)?"LitHuffN":("LitIdxN"+(name.isStatic()?"S":"")+(1+NBitInteger.octectsNeeded(6,_context.index(name)))))+
(huffman?"HuffVIdx":"LitVIdx");
}