459731 - Update for drafts hpack-11 and http2-17
This commit is contained in:
parent
e21d078d2b
commit
a147cee480
|
@ -262,7 +262,7 @@ public class HTTP2Client extends ContainerLifeCycle
|
|||
SslContextFactory sslContextFactory = (SslContextFactory)context.get(SslClientConnectionFactory.SSL_CONTEXT_FACTORY_CONTEXT_KEY);
|
||||
if (sslContextFactory != null)
|
||||
{
|
||||
ALPNClientConnectionFactory alpn = new ALPNClientConnectionFactory(getExecutor(), factory, "h2-14");
|
||||
ALPNClientConnectionFactory alpn = new ALPNClientConnectionFactory(getExecutor(), factory, "h2-17");
|
||||
factory = new SslClientConnectionFactory(sslContextFactory, getByteBufferPool(), getExecutor(), alpn);
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,15 @@ import org.eclipse.jetty.util.Trie;
|
|||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** HPACK - Header Compression for HTTP/2
|
||||
* <p>This class maintains the compression context for a single HTTP/2
|
||||
* connection. Specifically it holds the static and dynamic Header Field Tables
|
||||
* and the associated sizes and limits.
|
||||
* </p>
|
||||
* <p>It is compliant with draft 11 of the specification</p>
|
||||
*/
|
||||
public class HpackContext
|
||||
{
|
||||
public static final Logger LOG = Log.getLogger(HpackContext.class);
|
||||
|
|
|
@ -34,7 +34,8 @@ import org.eclipse.jetty.util.log.Logger;
|
|||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* This is not thread safe. May only be called by 1 thread at a time
|
||||
* Hpack Decoder
|
||||
* <p>This is not thread safe and may only be called by 1 thread at a time
|
||||
*/
|
||||
public class HpackDecoder
|
||||
{
|
||||
|
@ -46,6 +47,11 @@ public class HpackDecoder
|
|||
private final MetaDataBuilder _builder;
|
||||
private int _localMaxDynamicTableSize;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param localMaxDynamicTableSize The maximum allowed size of the local dynamic header field table.
|
||||
* @param maxHeaderSize The maximum allowed size of a headers block, expressed as total of all name and value characters.
|
||||
*/
|
||||
public HpackDecoder(int localMaxDynamicTableSize, int maxHeaderSize)
|
||||
{
|
||||
_context=new HpackContext(localMaxDynamicTableSize);
|
||||
|
@ -53,6 +59,11 @@ public class HpackDecoder
|
|||
_builder = new MetaDataBuilder(maxHeaderSize);
|
||||
}
|
||||
|
||||
public HpackContext getHpackContext()
|
||||
{
|
||||
return _context;
|
||||
}
|
||||
|
||||
public void setLocalMaxDynamicTableSize(int localMaxdynamciTableSize)
|
||||
{
|
||||
_localMaxDynamicTableSize=localMaxdynamciTableSize;
|
||||
|
|
|
@ -108,7 +108,7 @@ public class HpackEncoder
|
|||
_debug=LOG.isDebugEnabled();
|
||||
}
|
||||
|
||||
public HpackContext getContext()
|
||||
public HpackContext getHpackContext()
|
||||
{
|
||||
return _context;
|
||||
}
|
||||
|
|
|
@ -45,9 +45,13 @@ public class MetaDataBuilder
|
|||
|
||||
private HttpFields _fields = new HttpFields(10);
|
||||
|
||||
MetaDataBuilder(int maxSize)
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param maxHeadersSize The maximum size of the headers, expressed as total name and value characters.
|
||||
*/
|
||||
MetaDataBuilder(int maxHeadersSize)
|
||||
{
|
||||
_maxSize=maxSize;
|
||||
_maxSize=maxHeadersSize;
|
||||
}
|
||||
|
||||
/** Get the maxSize.
|
||||
|
|
|
@ -75,7 +75,7 @@ public class HpackEncoderTest
|
|||
assertThat(buffer.remaining(),Matchers.greaterThan(0));
|
||||
|
||||
// All are in the dynamic table
|
||||
Assert.assertEquals(4,encoder.getContext().size());
|
||||
Assert.assertEquals(4,encoder.getHpackContext().size());
|
||||
|
||||
// encode exact same fields again!
|
||||
BufferUtil.clearToFill(buffer);
|
||||
|
@ -83,7 +83,7 @@ public class HpackEncoderTest
|
|||
BufferUtil.flipToFlush(buffer,0);
|
||||
|
||||
// All are in the dynamic table
|
||||
Assert.assertEquals(4,encoder.getContext().size());
|
||||
Assert.assertEquals(4,encoder.getHpackContext().size());
|
||||
|
||||
// Add 4 more fields
|
||||
for (int i=4;i<=7;i++)
|
||||
|
@ -98,7 +98,7 @@ public class HpackEncoderTest
|
|||
assertThat(buffer.remaining(),Matchers.greaterThan(0));
|
||||
|
||||
// max dynamic table size reached
|
||||
Assert.assertEquals(5,encoder.getContext().size());
|
||||
Assert.assertEquals(5,encoder.getHpackContext().size());
|
||||
|
||||
|
||||
// remove some fields
|
||||
|
@ -114,7 +114,7 @@ public class HpackEncoderTest
|
|||
assertThat(buffer.remaining(),Matchers.greaterThan(0));
|
||||
|
||||
// max dynamic table size reached
|
||||
Assert.assertEquals(5,encoder.getContext().size());
|
||||
Assert.assertEquals(5,encoder.getHpackContext().size());
|
||||
|
||||
|
||||
// remove another fields
|
||||
|
@ -129,7 +129,7 @@ public class HpackEncoderTest
|
|||
assertThat(buffer.remaining(),Matchers.greaterThan(0));
|
||||
|
||||
// max dynamic table size reached
|
||||
Assert.assertEquals(5,encoder.getContext().size());
|
||||
Assert.assertEquals(5,encoder.getHpackContext().size());
|
||||
|
||||
|
||||
// re add the field
|
||||
|
@ -145,7 +145,7 @@ public class HpackEncoderTest
|
|||
assertThat(buffer.remaining(),Matchers.greaterThan(0));
|
||||
|
||||
// max dynamic table size reached
|
||||
Assert.assertEquals(5,encoder.getContext().size());
|
||||
Assert.assertEquals(5,encoder.getHpackContext().size());
|
||||
|
||||
}
|
||||
|
||||
|
@ -168,7 +168,7 @@ public class HpackEncoderTest
|
|||
assertThat(buffer.remaining(),Matchers.greaterThan(0));
|
||||
|
||||
// empty dynamic table
|
||||
Assert.assertEquals(0,encoder.getContext().size());
|
||||
Assert.assertEquals(0,encoder.getHpackContext().size());
|
||||
|
||||
|
||||
// encode again
|
||||
|
@ -180,7 +180,7 @@ public class HpackEncoderTest
|
|||
assertThat(buffer.remaining(),Matchers.greaterThan(0));
|
||||
|
||||
// empty dynamic table
|
||||
Assert.assertEquals(0,encoder.getContext().size());
|
||||
Assert.assertEquals(0,encoder.getHpackContext().size());
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -138,4 +138,49 @@ public class HpackTest
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@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());
|
||||
|
||||
|
||||
assertEquals(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);
|
||||
assertEquals(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());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ public abstract class AbstractHTTP2ServerConnectionFactory extends AbstractConne
|
|||
|
||||
public AbstractHTTP2ServerConnectionFactory(@Name("config") HttpConfiguration httpConfiguration)
|
||||
{
|
||||
super("h2-15","h2-14");
|
||||
super("h2-17","h2-16","h2-15","h2-14","h2");
|
||||
this.httpConfiguration = httpConfiguration;
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,6 @@ public class RawHTTP2ServerConnectionFactory extends AbstractHTTP2ServerConnecti
|
|||
@Override
|
||||
protected ServerParser newServerParser(ByteBufferPool byteBufferPool, ServerParser.Listener listener)
|
||||
{
|
||||
// TODO: make maxHeaderSize configurable.
|
||||
return new ServerParser(byteBufferPool, listener, getMaxDynamicTableSize(), 8192);
|
||||
return new ServerParser(byteBufferPool, listener, getMaxDynamicTableSize(), getHttpConfiguration().getRequestHeaderSize());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue