HpackContext { public Entry add(HttpField field) { Entry entry = new Entry(field); int size = entry.getSize(); if (size > maxDynamicTableSizeInBytes) { if (LOG.isDebugEnabled()) LOG.debug(String.format("HdrTbl[%x] !added size %d>%d", hashCode(), size, maxDynamicTableSizeInBytes)); dynamicTable.evictAll(); return null; } dynamicTableSizeInBytes += size; dynamicTable.add(entry); fieldMap.put(field, entry); nameMap.put(StringUtils.asciiToLowerCase(field.getName()), entry); if (LOG.isDebugEnabled()) LOG.debug(String.format("HdrTbl[%x] added %s", hashCode(), entry)); dynamicTable.evict(); return entry; } 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 testEmptyAdd() { HpackContext ctx = new HpackContext(0); HttpField field = new HttpField("foo", "bar"); assertNull(ctx.add(field)); }
@Test void testTooBigAdd() { HpackContext ctx = new HpackContext(37); HttpField field = new HttpField("foo", "bar"); assertNull(ctx.add(field)); }