HpackContext { public void resize(int newMaxDynamicTableSize) { if (LOG.isDebugEnabled()) LOG.debug(String.format("HdrTbl[%x] resized max=%d->%d", hashCode(), maxDynamicTableSizeInBytes, newMaxDynamicTableSize)); maxDynamicTableSizeInBytes = newMaxDynamicTableSize; dynamicTable.evict(); } HpackContext(int maxDynamicTableSize); void resize(int newMaxDynamicTableSize); Entry get(HttpField field); Entry get(String name); Entry get(int index); Entry get(HttpHeader header); static Entry getStatic(HttpHeader header); Entry add(HttpField field); int size(); int getDynamicTableSize(); int getMaxDynamicTableSize(); int index(Entry entry); static int staticIndex(HttpHeader header); @Override String toString(); static final String[][] STATIC_TABLE; static final int STATIC_SIZE; }
@Test void testResize() { HpackContext ctx = new HpackContext(38 * 5); HttpField[] field = { new HttpField("fo0", "b0r"), new HttpField("fo1", "b1r"), new HttpField("fo2", "b2r"), new HttpField("fo3", "b3r"), new HttpField("fo4", "b4r"), new HttpField("fo5", "b5r"), new HttpField("fo6", "b6r"), new HttpField("fo7", "b7r"), new HttpField("fo8", "b8r"), new HttpField("fo9", "b9r"), new HttpField("foA", "bAr"), }; Entry[] entry = new Entry[field.length]; for (int i = 0; i <= 4; i++) entry[i] = ctx.add(field[i]); assertEquals(5, ctx.size()); int index = 66; for (int i = 0; i <= 4; i++) { assertEquals(index, ctx.index(entry[i])); assertEquals(entry[i], ctx.get(index)); index--; } ctx.resize(38 * 2); assertEquals(2, ctx.size()); index = 63; for (int i = 3; i <= 4; i++) { assertEquals(index, ctx.index(entry[i])); assertEquals(entry[i], ctx.get(index)); index--; } ctx.resize(38 * 6 + 19); assertEquals(2, ctx.size()); index = 63; for (int i = 3; i <= 4; i++) { assertEquals(index, ctx.index(entry[i])); assertEquals(entry[i], ctx.get(index)); index--; } for (int i = 5; i <= 9; i++) entry[i] = ctx.add(field[i]); assertEquals(6, ctx.size()); index = 67; for (int i = 4; i <= 9; i++) { assertEquals(index, ctx.index(entry[i])); assertEquals(entry[i], ctx.get(index)); index--; } ctx.resize(38 * 100); assertEquals(6, ctx.size()); index = 67; for (int i = 4; i <= 9; i++) { assertEquals(index, ctx.index(entry[i])); assertEquals(entry[i], ctx.get(index)); index--; } for (int i = 0; i < 50; i++) ctx.add(new HttpField("n" + i, "v" + i)); index = 67 + 50; for (int i = 4; i <= 9; i++) { assertEquals(index, ctx.index(entry[i])); assertEquals(entry[i], ctx.get(index)); index--; } }