(tomcat) branch 9.0.x updated: Make HPACK encoding test deterministic

[email protected]
Newsgroups gmane.comp.jakarta.tomcat.devel
Message-ID <[email protected]>
This is an automated email from the ASF dual-hosted git repository.

markt-asf pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/9.0.x by this push:
     new 92cb782c5f Make HPACK encoding test deterministic
92cb782c5f is described below

commit 92cb782c5f81a428de05a31baa328380bdd6fee9
Author: sainadh777 <[email protected]>
AuthorDate: Tue Aug 4 22:19:51 2026 -0700

    Make HPACK encoding test deterministic
---
 java/org/apache/coyote/http2/HpackEncoder.java |  8 ++++++--
 test/org/apache/coyote/http2/TestHpack.java    | 21 ++++++++++++++++++---
 2 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/java/org/apache/coyote/http2/HpackEncoder.java b/java/org/apache/coyote/http2/HpackEncoder.java
index 8492371b9b..bd7a55e506 100644
--- a/java/org/apache/coyote/http2/HpackEncoder.java
+++ b/java/org/apache/coyote/http2/HpackEncoder.java
@@ -112,7 +112,11 @@ class HpackEncoder {
     private final HpackHeaderFunction hpackHeaderFunction;
 
     HpackEncoder() {
-        this.hpackHeaderFunction = DEFAULT_HEADER_FUNCTION;
+        this(DEFAULT_HEADER_FUNCTION);
+    }
+
+    HpackEncoder(HpackHeaderFunction hpackHeaderFunction) {
+        this.hpackHeaderFunction = hpackHeaderFunction;
     }
 
     /**
@@ -401,7 +405,7 @@ class HpackEncoder {
         }
     }
 
-    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 a96453171c..6525f214ce 100644
--- a/test/org/apache/coyote/http2/TestHpack.java
+++ b/test/org/apache/coyote/http2/TestHpack.java
@@ -32,11 +32,26 @@ public class TestHpack {
         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);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.