This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push:
new a74b9f4775 Refactor to reduce code duplication
a74b9f4775 is described below
commit a74b9f477574926df3e88fdfa517ee2e773162da
Author: Mark Thomas <[email protected]>
AuthorDate: Wed Apr 1 17:45:47 2026 +0100
Refactor to reduce code duplication
---
java/org/apache/coyote/http2/HpackDecoder.java | 17 ++++-------------
webapps/docs/changelog.xml | 4 ++++
2 files changed, 8 insertions(+), 13 deletions(-)
diff --git a/java/org/apache/coyote/http2/HpackDecoder.java
b/java/org/apache/coyote/http2/HpackDecoder.java
index 528f71481a..b9c889eec0 100644
--- a/java/org/apache/coyote/http2/HpackDecoder.java
+++ b/java/org/apache/coyote/http2/HpackDecoder.java
@@ -238,10 +238,6 @@ public class HpackDecoder {
return Hpack.STATIC_TABLE[index].name;
} else {
// index is 1 based
- if (index > Hpack.STATIC_TABLE_LENGTH + filledTableSlots) {
- throw new
HpackException(sm.getString("hpackdecoder.headerTableIndexInvalid",
Integer.valueOf(index),
- Integer.valueOf(Hpack.STATIC_TABLE_LENGTH),
Integer.valueOf(filledTableSlots)));
- }
int adjustedIndex = getRealIndex(index -
Hpack.STATIC_TABLE_LENGTH);
Hpack.HeaderField res = headerTable[adjustedIndex];
if (res == null) {
@@ -263,10 +259,6 @@ public class HpackDecoder {
addStaticTableEntry(index);
} else {
// index is 1 based
- if (index > Hpack.STATIC_TABLE_LENGTH + filledTableSlots) {
- throw new
HpackException(sm.getString("hpackdecoder.headerTableIndexInvalid",
Integer.valueOf(index),
- Integer.valueOf(Hpack.STATIC_TABLE_LENGTH),
Integer.valueOf(filledTableSlots)));
- }
int adjustedIndex = getRealIndex(index -
Hpack.STATIC_TABLE_LENGTH);
if (log.isTraceEnabled()) {
log.trace(sm.getString("hpackdecoder.useDynamic",
Integer.valueOf(adjustedIndex)));
@@ -287,15 +279,14 @@ public class HpackDecoder {
* @return the real index into the array
*/
int getRealIndex(int index) throws HpackException {
- // the index is one based, but our table is zero based, hence -1
- // also because of our ring buffer set up the indexes are reversed
+ // The index is one based, but our table is zero based
+ // Also, because of our ring buffer set up, the indexes are reversed
// index = 1 is at position firstSlotPosition + filledSlots
- int realIndex = (firstSlotPosition + (filledTableSlots - index)) %
headerTable.length;
- if (realIndex < 0) {
+ if (index < 1 || index > filledTableSlots) {
throw new
HpackException(sm.getString("hpackdecoder.headerTableIndexInvalid",
Integer.valueOf(index),
Integer.valueOf(Hpack.STATIC_TABLE_LENGTH),
Integer.valueOf(filledTableSlots)));
}
- return realIndex;
+ return (firstSlotPosition + (filledTableSlots - index)) %
headerTable.length;
}
private void addStaticTableEntry(int index) throws HpackException {
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 9dc2cdf04b..30ce27615d 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -238,6 +238,10 @@
clearing the previous value whether the new value is valid or not and
ignoring any invalid new value. (markt)
</fix>
+ <scode>
+ Refactor the calculation of the real index in the HPACK dynamic header
+ table implementation to reduce code duplication. (markt)
+ </scode>
</changelog>
</subsection>
<subsection name="Jasper">
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]