DefaultHttp2HeadersDecoder implements Http2HeadersDecoder, Http2HeadersDecoder.Configuration { @Override public Http2Headers decodeHeaders(ByteBuf headerBlock) throws Http2Exception { InputStream in = new ByteBufInputStream(headerBlock); try { final Http2Headers headers = new DefaultHttp2Headers(validateHeaders, (int) headerArraySizeAccumulator); HeaderListener listener = new HeaderListener() { @Override public void addHeader(byte[] key, byte[] value, boolean sensitive) { headers.add(new AsciiString(key, false), new AsciiString(value, false)); } }; decoder.decode(in, listener); if (decoder.endHeaderBlock()) { maxHeaderSizeExceeded(); } if (headers.size() > headerTable.maxHeaderListSize()) { throw connectionError(PROTOCOL_ERROR, "Number of headers (%d) exceeds maxHeaderListSize (%d)", headers.size(), headerTable.maxHeaderListSize()); } headerArraySizeAccumulator = HEADERS_COUNT_WEIGHT_NEW * headers.size() + HEADERS_COUNT_WEIGHT_HISTORICAL * headerArraySizeAccumulator; return headers; } catch (IOException e) { throw connectionError(COMPRESSION_ERROR, e, e.getMessage()); } catch (Http2Exception e) { throw e; } catch (Throwable e) { throw connectionError(COMPRESSION_ERROR, e, e.getMessage()); } finally { try { in.close(); } catch (IOException e) { throw connectionError(INTERNAL_ERROR, e, e.getMessage()); } } } DefaultHttp2HeadersDecoder();  DefaultHttp2HeadersDecoder(boolean validateHeaders);  DefaultHttp2HeadersDecoder(int maxHeaderSize, int maxHeaderTableSize, boolean validateHeaders); @Override Http2HeaderTable headerTable(); @Override int maxHeaderSize(); @Override Configuration configuration(); @Override Http2Headers decodeHeaders(ByteBuf headerBlock);  }
@Test public void decodeShouldSucceed() throws Exception { ByteBuf buf = encode(b(":method"), b("GET"), b("akey"), b("avalue"), randomBytes(), randomBytes()); try { Http2Headers headers = decoder.decodeHeaders(buf); assertEquals(3, headers.size()); assertEquals("GET", headers.method().toString()); assertEquals("avalue", headers.get(new AsciiString("akey")).toString()); } finally { buf.release(); } }
@Test(expected = Http2Exception.class) public void testExceedHeaderSize() throws Exception { ByteBuf buf = encode(randomBytes(DEFAULT_MAX_HEADER_SIZE), randomBytes(1)); try { decoder.decodeHeaders(buf); fail(); } finally { buf.release(); } }