improved static encoding strategy

This commit is contained in:
Greg Wilkins 2014-06-17 19:54:21 +02:00
parent 7fa4f1e9f8
commit e115dee62f
2 changed files with 22 additions and 13 deletions

View File

@ -120,29 +120,32 @@ public class HpackContext
switch(i) switch(i)
{ {
case 2: case 2:
entry=new StaticEntry(i,new StaticValueHttpField(STATIC_TABLE[i][0],STATIC_TABLE[i][1],HttpMethod.GET)); entry=new StaticEntry(i,new StaticValueHttpField(STATIC_TABLE[i][0],STATIC_TABLE[i][1],HttpMethod.GET),true);
break; break;
case 3: case 3:
entry=new StaticEntry(i,new StaticValueHttpField(STATIC_TABLE[i][0],STATIC_TABLE[i][1],HttpMethod.POST)); entry=new StaticEntry(i,new StaticValueHttpField(STATIC_TABLE[i][0],STATIC_TABLE[i][1],HttpMethod.POST),false);
break; break;
case 6: case 6:
entry=new StaticEntry(i,new StaticValueHttpField(STATIC_TABLE[i][0],STATIC_TABLE[i][1],HttpScheme.HTTP)); entry=new StaticEntry(i,new StaticValueHttpField(STATIC_TABLE[i][0],STATIC_TABLE[i][1],HttpScheme.HTTP),true);
break; break;
case 7: case 7:
entry=new StaticEntry(i,new StaticValueHttpField(STATIC_TABLE[i][0],STATIC_TABLE[i][1],HttpScheme.HTTPS)); entry=new StaticEntry(i,new StaticValueHttpField(STATIC_TABLE[i][0],STATIC_TABLE[i][1],HttpScheme.HTTPS),false);
break; break;
case 8: case 8:
case 11:
entry=new StaticEntry(i,new StaticValueHttpField(STATIC_TABLE[i][0],STATIC_TABLE[i][1],Integer.valueOf(STATIC_TABLE[i][1])),true);
break;
case 9: case 9:
case 10: case 10:
case 11:
case 12: case 12:
case 13: case 13:
case 14: case 14:
entry=new StaticEntry(i,new StaticValueHttpField(STATIC_TABLE[i][0],STATIC_TABLE[i][1],Integer.valueOf(STATIC_TABLE[i][1]))); entry=new StaticEntry(i,new StaticValueHttpField(STATIC_TABLE[i][0],STATIC_TABLE[i][1],Integer.valueOf(STATIC_TABLE[i][1])),false);
break; break;
default: default:
entry=new StaticEntry(i,new HttpField(STATIC_TABLE[i][0],STATIC_TABLE[i][1])); entry=new StaticEntry(i,new HttpField(STATIC_TABLE[i][0],STATIC_TABLE[i][1]),true);
} }
__staticTable[i]=entry; __staticTable[i]=entry;
@ -160,8 +163,6 @@ public class HpackContext
} }
} }
public static final StaticEntry METHOD_GET=__staticTable[2];
public static final StaticEntry STATUS_200=__staticTable[8];
private int _maxHeaderTableSizeInBytes; private int _maxHeaderTableSizeInBytes;
@ -566,9 +567,10 @@ public class HpackContext
public static class StaticEntry extends Entry public static class StaticEntry extends Entry
{ {
final byte[] _huffmanValue; private final byte[] _huffmanValue;
private final boolean _useRefSet;
StaticEntry(int index,HttpField field) StaticEntry(int index,HttpField field,boolean useRefSet)
{ {
super(index,field); super(index,field);
String value = field.getValue(); String value = field.getValue();
@ -588,6 +590,7 @@ public class HpackContext
} }
else else
_huffmanValue=null; _huffmanValue=null;
_useRefSet=useRefSet;
} }
@Override @Override
@ -596,6 +599,11 @@ public class HpackContext
return true; return true;
} }
public boolean useRefSet()
{
return _useRefSet;
}
@Override @Override
public byte[] getStaticHuffmanValue() public byte[] getStaticHuffmanValue()
{ {

View File

@ -27,6 +27,7 @@ import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpStatus; import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.http.MetaData; import org.eclipse.jetty.http.MetaData;
import org.eclipse.jetty.http2.hpack.HpackContext.Entry; import org.eclipse.jetty.http2.hpack.HpackContext.Entry;
import org.eclipse.jetty.http2.hpack.HpackContext.StaticEntry;
import org.eclipse.jetty.io.ByteBufferPool.Lease; import org.eclipse.jetty.io.ByteBufferPool.Lease;
import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.TypeUtil; import org.eclipse.jetty.util.TypeUtil;
@ -204,9 +205,9 @@ public class HpackEncoder
// TODO Strategy decision to make! // TODO Strategy decision to make!
// Should we add to reference set or just always send as indexed? // Should we add to reference set or just always send as indexed?
if (entry==HpackContext.METHOD_GET || entry==HpackContext.STATUS_200) if (((StaticEntry)entry).useRefSet())
{ {
// :status: 200 and :method: GET are worthwhile putting into ref set. // entries like :status: 200 and :method: GET are worthwhile putting into ref set.
// as they are likely to be repeated. // as they are likely to be repeated.
int index=_context.index(entry); int index=_context.index(entry);
buffer.put((byte)0x80); buffer.put((byte)0x80);