updated hpack for draft 10 name changes
This commit is contained in:
parent
4296d84a7b
commit
c3472f01c4
|
@ -67,7 +67,7 @@ public class Generator
|
|||
|
||||
public void setHeaderTableSize(int headerTableSize)
|
||||
{
|
||||
hpackEncoder.setRemoteMaxHeaderTableSize(headerTableSize);
|
||||
hpackEncoder.setRemoteMaxDynamicTableSize(headerTableSize);
|
||||
}
|
||||
|
||||
public void setMaxFrameSize(int maxFrameSize)
|
||||
|
|
|
@ -45,13 +45,13 @@ public class Parser
|
|||
private final BodyParser[] bodyParsers;
|
||||
private State state = State.HEADER;
|
||||
|
||||
public Parser(ByteBufferPool byteBufferPool, Listener listener, int maxHeaderTableSize, int maxHeaderSize)
|
||||
public Parser(ByteBufferPool byteBufferPool, Listener listener, int maxDynamicTableSize, int maxHeaderSize)
|
||||
{
|
||||
this.listener = listener;
|
||||
this.headerParser = new HeaderParser();
|
||||
this.bodyParsers = new BodyParser[FrameType.values().length];
|
||||
|
||||
HeaderBlockParser headerBlockParser = new HeaderBlockParser(byteBufferPool, new HpackDecoder(maxHeaderTableSize, maxHeaderSize));
|
||||
HeaderBlockParser headerBlockParser = new HeaderBlockParser(byteBufferPool, new HpackDecoder(maxDynamicTableSize, maxHeaderSize));
|
||||
|
||||
bodyParsers[FrameType.DATA.getType()] = new DataBodyParser(headerParser, listener);
|
||||
bodyParsers[FrameType.HEADERS.getType()] = new HeadersBodyParser(headerParser, listener, headerBlockParser);
|
||||
|
|
|
@ -33,9 +33,9 @@ public class ServerParser extends Parser
|
|||
private final PrefaceParser prefaceParser;
|
||||
private State state = State.PREFACE;
|
||||
|
||||
public ServerParser(ByteBufferPool byteBufferPool, Listener listener, int maxHeaderTableSize, int maxHeaderSize)
|
||||
public ServerParser(ByteBufferPool byteBufferPool, Listener listener, int maxDynamicTableSize, int maxHeaderSize)
|
||||
{
|
||||
super(byteBufferPool, listener, maxHeaderTableSize, maxHeaderSize);
|
||||
super(byteBufferPool, listener, maxDynamicTableSize, maxHeaderSize);
|
||||
this.listener = listener;
|
||||
this.prefaceParser = new PrefaceParser(listener);
|
||||
}
|
||||
|
|
|
@ -267,7 +267,7 @@ public class HpackContext
|
|||
}
|
||||
|
||||
/**
|
||||
* @return Current Header table size in entries
|
||||
* @return Current dynamic table size in entries
|
||||
*/
|
||||
public int size()
|
||||
{
|
||||
|
@ -275,15 +275,15 @@ public class HpackContext
|
|||
}
|
||||
|
||||
/**
|
||||
* @return Current Header table size in Octets
|
||||
* @return Current Dynamic table size in Octets
|
||||
*/
|
||||
public int getHeaderTableSize()
|
||||
public int getDynamicTableSize()
|
||||
{
|
||||
return _dynamicTableSizeInBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Max Header table size in Octets
|
||||
* @return Max Dynamic table size in Octets
|
||||
*/
|
||||
public int getMaxDynamicTableSize()
|
||||
{
|
||||
|
|
|
@ -232,7 +232,7 @@ public class HpackDecoder
|
|||
// if indexed
|
||||
if (indexed)
|
||||
{
|
||||
// add to header table
|
||||
// add to dynamic table
|
||||
_context.add(field);
|
||||
}
|
||||
|
||||
|
|
|
@ -95,16 +95,16 @@ public class HpackEncoder
|
|||
this(4096,4096);
|
||||
}
|
||||
|
||||
public HpackEncoder(int localMaxHeaderTableSize)
|
||||
public HpackEncoder(int localMaxDynamicTableSize)
|
||||
{
|
||||
this(localMaxHeaderTableSize,4096);
|
||||
this(localMaxDynamicTableSize,4096);
|
||||
}
|
||||
|
||||
public HpackEncoder(int localMaxHeaderTableSize,int remoteMaxHeaderTableSize)
|
||||
public HpackEncoder(int localMaxDynamicTableSize,int remoteMaxDynamicTableSize)
|
||||
{
|
||||
_context=new HpackContext(remoteMaxHeaderTableSize);
|
||||
_remoteMaxDynamicTableSize=remoteMaxHeaderTableSize;
|
||||
_localMaxDynamicTableSize=localMaxHeaderTableSize;
|
||||
_context=new HpackContext(remoteMaxDynamicTableSize);
|
||||
_remoteMaxDynamicTableSize=remoteMaxDynamicTableSize;
|
||||
_localMaxDynamicTableSize=localMaxDynamicTableSize;
|
||||
_debug=LOG.isDebugEnabled();
|
||||
}
|
||||
|
||||
|
@ -113,14 +113,14 @@ public class HpackEncoder
|
|||
return _context;
|
||||
}
|
||||
|
||||
public void setRemoteMaxHeaderTableSize(int remoteMaxHeaderTableSize)
|
||||
public void setRemoteMaxDynamicTableSize(int remoteMaxDynamicTableSize)
|
||||
{
|
||||
_remoteMaxDynamicTableSize=remoteMaxHeaderTableSize;
|
||||
_remoteMaxDynamicTableSize=remoteMaxDynamicTableSize;
|
||||
}
|
||||
|
||||
public void setLocalMaxHeaderTableSize(int localMaxHeaderTableSize)
|
||||
public void setLocalMaxDynamicTableSize(int localMaxDynamicTableSize)
|
||||
{
|
||||
_localMaxDynamicTableSize=localMaxHeaderTableSize;
|
||||
_localMaxDynamicTableSize=localMaxDynamicTableSize;
|
||||
}
|
||||
|
||||
// TODO better handling of buffer size
|
||||
|
@ -140,7 +140,7 @@ public class HpackEncoder
|
|||
|
||||
int pos = buffer.position();
|
||||
|
||||
// Check the header table sizes!
|
||||
// Check the dynamic table sizes!
|
||||
int maxDynamicTableSize=Math.min(_remoteMaxDynamicTableSize,_localMaxDynamicTableSize);
|
||||
if (maxDynamicTableSize!=_context.getMaxDynamicTableSize())
|
||||
encodeMaxDynamicTableSize(buffer,maxDynamicTableSize);
|
||||
|
|
|
@ -140,7 +140,7 @@ public class HpackContextTest
|
|||
assertEquals(methodGet,ctx.get(methodGet).getHttpField());
|
||||
assertTrue(ctx.get(methodGet).isStatic());
|
||||
|
||||
// Add static version to header table
|
||||
// Add static version to dynamic table
|
||||
Entry e0=ctx.add(ctx.get(methodGet).getHttpField());
|
||||
|
||||
// Look again and should see dynamic version
|
||||
|
|
|
@ -74,7 +74,7 @@ public class HpackEncoderTest
|
|||
// something was encoded!
|
||||
assertThat(buffer.remaining(),Matchers.greaterThan(0));
|
||||
|
||||
// All are in the header table
|
||||
// All are in the dynamic table
|
||||
Assert.assertEquals(4,encoder.getContext().size());
|
||||
|
||||
// encode exact same fields again!
|
||||
|
@ -82,7 +82,7 @@ public class HpackEncoderTest
|
|||
encoder.encode(buffer,new MetaData(HttpVersion.HTTP_2,fields));
|
||||
BufferUtil.flipToFlush(buffer,0);
|
||||
|
||||
// All are in the header table
|
||||
// All are in the dynamic table
|
||||
Assert.assertEquals(4,encoder.getContext().size());
|
||||
|
||||
// Add 4 more fields
|
||||
|
@ -97,7 +97,7 @@ public class HpackEncoderTest
|
|||
// something was encoded!
|
||||
assertThat(buffer.remaining(),Matchers.greaterThan(0));
|
||||
|
||||
// max header table size reached
|
||||
// max dynamic table size reached
|
||||
Assert.assertEquals(5,encoder.getContext().size());
|
||||
|
||||
|
||||
|
@ -113,7 +113,7 @@ public class HpackEncoderTest
|
|||
// something was encoded!
|
||||
assertThat(buffer.remaining(),Matchers.greaterThan(0));
|
||||
|
||||
// max header table size reached
|
||||
// max dynamic table size reached
|
||||
Assert.assertEquals(5,encoder.getContext().size());
|
||||
|
||||
|
||||
|
@ -128,7 +128,7 @@ public class HpackEncoderTest
|
|||
// something was encoded!
|
||||
assertThat(buffer.remaining(),Matchers.greaterThan(0));
|
||||
|
||||
// max header table size reached
|
||||
// max dynamic table size reached
|
||||
Assert.assertEquals(5,encoder.getContext().size());
|
||||
|
||||
|
||||
|
@ -144,7 +144,7 @@ public class HpackEncoderTest
|
|||
// something was encoded!
|
||||
assertThat(buffer.remaining(),Matchers.greaterThan(0));
|
||||
|
||||
// max header table size reached
|
||||
// max dynamic table size reached
|
||||
Assert.assertEquals(5,encoder.getContext().size());
|
||||
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ public class HpackEncoderTest
|
|||
// something was encoded!
|
||||
assertThat(buffer.remaining(),Matchers.greaterThan(0));
|
||||
|
||||
// empty header table
|
||||
// empty dynamic table
|
||||
Assert.assertEquals(0,encoder.getContext().size());
|
||||
|
||||
|
||||
|
@ -179,7 +179,7 @@ public class HpackEncoderTest
|
|||
// something was encoded!
|
||||
assertThat(buffer.remaining(),Matchers.greaterThan(0));
|
||||
|
||||
// empty header table
|
||||
// empty dynamic table
|
||||
Assert.assertEquals(0,encoder.getContext().size());
|
||||
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ import org.junit.Test;
|
|||
|
||||
public class HpackPerfTest
|
||||
{
|
||||
int _maxHeaderTableSize=4*1024;
|
||||
int _maxDynamicTableSize=4*1024;
|
||||
int _unencodedSize;
|
||||
int _encodedSize;
|
||||
|
||||
|
@ -52,17 +52,17 @@ public class HpackPerfTest
|
|||
@After
|
||||
public void after()
|
||||
{
|
||||
System.err.printf("headertable=%d unencoded=%d encoded=%d p=%3.1f%%%n",_maxHeaderTableSize,_unencodedSize,_encodedSize,100.0*_encodedSize/_unencodedSize);
|
||||
System.err.printf("dynamictable=%d unencoded=%d encoded=%d p=%3.1f%%%n",_maxDynamicTableSize,_unencodedSize,_encodedSize,100.0*_encodedSize/_unencodedSize);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleTest() throws Exception
|
||||
{
|
||||
runStories(_maxHeaderTableSize);
|
||||
runStories(_maxDynamicTableSize);
|
||||
}
|
||||
|
||||
private void runStories(int maxHeaderTableSize) throws Exception
|
||||
private void runStories(int maxDynamicTableSize) throws Exception
|
||||
{
|
||||
// Find files
|
||||
File data = MavenTestingUtils.getTestResourceDir("data");
|
||||
|
@ -101,7 +101,7 @@ public class HpackPerfTest
|
|||
{
|
||||
if (type.equals(story.get("context")))
|
||||
{
|
||||
HpackEncoder encoder = new HpackEncoder(_maxHeaderTableSize,_maxHeaderTableSize);
|
||||
HpackEncoder encoder = new HpackEncoder(_maxDynamicTableSize,_maxDynamicTableSize);
|
||||
|
||||
// System.err.println(story);
|
||||
Object[] cases = (Object[])story.get("cases");
|
||||
|
|
|
@ -34,7 +34,7 @@ import org.eclipse.jetty.server.Connector;
|
|||
public abstract class AbstractHTTP2ServerConnectionFactory extends AbstractConnectionFactory
|
||||
{
|
||||
private boolean dispatchIO = true;
|
||||
private int maxHeaderTableSize = 4096;
|
||||
private int maxDynamicTableSize = 4096;
|
||||
private int initialStreamWindow = FlowControl.DEFAULT_WINDOW_SIZE;
|
||||
private int maxConcurrentStreams = -1;
|
||||
|
||||
|
@ -53,14 +53,14 @@ public abstract class AbstractHTTP2ServerConnectionFactory extends AbstractConne
|
|||
this.dispatchIO = dispatchIO;
|
||||
}
|
||||
|
||||
public int getMaxHeaderTableSize()
|
||||
public int getMaxDynamicTableSize()
|
||||
{
|
||||
return maxHeaderTableSize;
|
||||
return maxDynamicTableSize;
|
||||
}
|
||||
|
||||
public void setMaxHeaderTableSize(int maxHeaderTableSize)
|
||||
{
|
||||
this.maxHeaderTableSize = maxHeaderTableSize;
|
||||
this.maxDynamicTableSize = maxHeaderTableSize;
|
||||
}
|
||||
|
||||
public int getInitialStreamWindow()
|
||||
|
@ -88,7 +88,7 @@ public abstract class AbstractHTTP2ServerConnectionFactory extends AbstractConne
|
|||
{
|
||||
ServerSessionListener listener = newSessionListener(connector, endPoint);
|
||||
|
||||
Generator generator = new Generator(connector.getByteBufferPool(), getMaxHeaderTableSize());
|
||||
Generator generator = new Generator(connector.getByteBufferPool(), getMaxDynamicTableSize());
|
||||
HTTP2ServerSession session = new HTTP2ServerSession(connector.getScheduler(), endPoint, generator, listener,
|
||||
new HTTP2FlowControl(getInitialStreamWindow()));
|
||||
session.setMaxLocalStreams(getMaxConcurrentStreams());
|
||||
|
|
|
@ -62,7 +62,7 @@ public class HTTP2ServerConnectionFactory extends AbstractHTTP2ServerConnectionF
|
|||
@Override
|
||||
protected ServerParser newServerParser(ByteBufferPool byteBufferPool, ServerParser.Listener listener)
|
||||
{
|
||||
return new ServerParser(byteBufferPool, listener, getMaxHeaderTableSize(), httpConfiguration.getRequestHeaderSize());
|
||||
return new ServerParser(byteBufferPool, listener, getMaxDynamicTableSize(), httpConfiguration.getRequestHeaderSize());
|
||||
}
|
||||
|
||||
|
||||
|
@ -87,7 +87,7 @@ public class HTTP2ServerConnectionFactory extends AbstractHTTP2ServerConnectionF
|
|||
public Map<Integer, Integer> onPreface(Session session)
|
||||
{
|
||||
Map<Integer, Integer> settings = new HashMap<>();
|
||||
settings.put(SettingsFrame.HEADER_TABLE_SIZE, getMaxHeaderTableSize());
|
||||
settings.put(SettingsFrame.HEADER_TABLE_SIZE, getMaxDynamicTableSize());
|
||||
settings.put(SettingsFrame.INITIAL_WINDOW_SIZE, getInitialStreamWindow());
|
||||
int maxConcurrentStreams = getMaxConcurrentStreams();
|
||||
if (maxConcurrentStreams >= 0)
|
||||
|
|
|
@ -43,6 +43,6 @@ public class RawHTTP2ServerConnectionFactory extends AbstractHTTP2ServerConnecti
|
|||
protected ServerParser newServerParser(ByteBufferPool byteBufferPool, ServerParser.Listener listener)
|
||||
{
|
||||
// TODO: make maxHeaderSize configurable.
|
||||
return new ServerParser(byteBufferPool, listener, getMaxHeaderTableSize(), 8192);
|
||||
return new ServerParser(byteBufferPool, listener, getMaxDynamicTableSize(), 8192);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue