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

[email protected]
Newsgroups gmane.comp.jakarta.tomcat.devel
Message-ID <178644435960.1633088.15827467319816078455@gitbox3-he-fi.apache.org>
This is an automated email from the ASF dual-hosted git repository.

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


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

commit d1d3a04b74f2263efc74bddbc4c98fe0c157d663
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 97aeace111..3af766cb47 100644
--- a/java/org/apache/coyote/http2/HpackEncoder.java
+++ b/java/org/apache/coyote/http2/HpackEncoder.java
@@ -109,7 +109,11 @@ class HpackEncoder {
     private final HpackHeaderFunction hpackHeaderFunction;
 
     HpackEncoder() {
-        this.hpackHeaderFunction = DEFAULT_HEADER_FUNCTION;
+        this(DEFAULT_HEADER_FUNCTION);
+    }
+
+    HpackEncoder(HpackHeaderFunction hpackHeaderFunction) {
+        this.hpackHeaderFunction = hpackHeaderFunction;
     }
 
     /**
@@ -398,7 +402,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.