diff --git a/java/org/apache/coyote/http2/HpackEncoder.java b/java/org/apache/coyote/http2/HpackEncoder.java index 97aeace111f2..3af766cb472c 100644 --- a/java/org/apache/coyote/http2/HpackEncoder.java +++ b/java/org/apache/coyote/http2/HpackEncoder.java @@ -109,7 +109,11 @@ public boolean shouldUseHuffman(String header) { private final HpackHeaderFunction hpackHeaderFunction; HpackEncoder() { - this.hpackHeaderFunction = DEFAULT_HEADER_FUNCTION; + this(DEFAULT_HEADER_FUNCTION); + } + + HpackEncoder(HpackHeaderFunction hpackHeaderFunction) { + this.hpackHeaderFunction = hpackHeaderFunction; } /** @@ -398,7 +402,7 @@ int getPosition() { } } - private interface HpackHeaderFunction { + interface HpackHeaderFunction { boolean shouldUseIndexing(String header, String value); /** diff --git a/test/org/apache/coyote/http2/TestHpack.java b/test/org/apache/coyote/http2/TestHpack.java index a96453171cfe..6525f214ce5d 100644 --- a/test/org/apache/coyote/http2/TestHpack.java +++ b/test/org/apache/coyote/http2/TestHpack.java @@ -32,11 +32,26 @@ public void testEncode() throws Exception { headers.setValue(":status").setString("200"); headers.setValue("header2").setString("value2"); ByteBuffer output = ByteBuffer.allocate(512); - HpackEncoder encoder = new HpackEncoder(); + HpackEncoder encoder = new HpackEncoder(new HpackEncoder.HpackHeaderFunction() { + + @Override + public boolean shouldUseIndexing(String header, String value) { + return true; + } + + @Override + public boolean shouldUseHuffman(String header, String value) { + return true; + } + + @Override + public boolean shouldUseHuffman(String header) { + return true; + } + }); encoder.encode(headers, output); output.flip(); - // Size is supposed to be 33 without huffman, or 27 with it - // TODO: use the HpackHeaderFunction to enable huffman predictably + // Size is 27 with Huffman encoding Assert.assertEquals(27, output.remaining()); output.clear(); encoder.encode(headers, output);