You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2021/06/07 19:39:04 UTC

[tomcat] branch 10.0.x updated: Add debug logging for HPACK decoding

This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/10.0.x by this push:
     new d5c8c92  Add debug logging for HPACK decoding
d5c8c92 is described below

commit d5c8c92c842d471fa4899d84371d0ec81921131d
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Mon Jun 7 20:38:13 2021 +0100

    Add debug logging for HPACK decoding
---
 java/org/apache/coyote/http2/HpackDecoder.java       | 20 +++++++++++++++++++-
 java/org/apache/coyote/http2/LocalStrings.properties |  5 +++++
 webapps/docs/changelog.xml                           |  3 +++
 3 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/java/org/apache/coyote/http2/HpackDecoder.java b/java/org/apache/coyote/http2/HpackDecoder.java
index 02802ad..badebad 100644
--- a/java/org/apache/coyote/http2/HpackDecoder.java
+++ b/java/org/apache/coyote/http2/HpackDecoder.java
@@ -18,6 +18,8 @@ package org.apache.coyote.http2;
 
 import java.nio.ByteBuffer;
 
+import org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
 import org.apache.tomcat.util.res.StringManager;
 
 /**
@@ -25,7 +27,8 @@ import org.apache.tomcat.util.res.StringManager;
  */
 public class HpackDecoder {
 
-    protected static final StringManager sm = StringManager.getManager(HpackDecoder.class);
+    private static final Log log = LogFactory.getLog(HpackDecoder.class);
+    private static final StringManager sm = StringManager.getManager(HpackDecoder.class);
 
     private static final int DEFAULT_RING_BUFFER_SIZE = 10;
 
@@ -263,6 +266,9 @@ public class HpackDecoder {
             addStaticTableEntry(index);
         } else {
             int adjustedIndex = getRealIndex(index - Hpack.STATIC_TABLE_LENGTH);
+            if (log.isDebugEnabled()) {
+                log.debug(sm.getString("hpackdecoder.useDynamic", Integer.valueOf(adjustedIndex)));
+            }
             Hpack.HeaderField headerField = headerTable[adjustedIndex];
             emitHeader(headerField.name, headerField.value);
         }
@@ -292,12 +298,18 @@ public class HpackDecoder {
 
     private void addStaticTableEntry(int index) throws HpackException {
         //adds an entry from the static table.
+        if (log.isDebugEnabled()) {
+            log.debug(sm.getString("hpackdecoder.useStatic", Integer.valueOf(index)));
+        }
         Hpack.HeaderField entry = Hpack.STATIC_TABLE[index];
         emitHeader(entry.name, (entry.value == null) ? "" : entry.value);
     }
 
     private void addEntryToHeaderTable(Hpack.HeaderField entry) {
         if (entry.size > maxMemorySizeSoft) {
+            if (log.isDebugEnabled()) {
+                log.debug(sm.getString("hpackdecoder.clearDynamic"));
+            }
             //it is to big to fit, so we just completely clear the table.
             while (filledTableSlots > 0) {
                 headerTable[firstSlotPosition] = null;
@@ -314,6 +326,9 @@ public class HpackDecoder {
         int newTableSlots = filledTableSlots + 1;
         int tableLength = headerTable.length;
         int index = (firstSlotPosition + filledTableSlots) % tableLength;
+        if (log.isDebugEnabled()) {
+            log.debug(sm.getString("hpackdecoder.addDynamic", Integer.valueOf(index), entry.name, entry.value));
+        }
         headerTable[index] = entry;
         int newSize = currentMemorySize + entry.size;
         while (newSize > maxMemorySizeSoft) {
@@ -424,6 +439,9 @@ public class HpackDecoder {
         int inc = 3 + name.length() + value.length();
         headerSize += inc;
         if (!isHeaderCountExceeded() && !isHeaderSizeExceeded(0)) {
+            if (log.isDebugEnabled()) {
+                log.debug(sm.getString("hpackdecoder.emitHeader", name, value));
+            }
             headerEmitter.emitHeader(name, value);
         }
     }
diff --git a/java/org/apache/coyote/http2/LocalStrings.properties b/java/org/apache/coyote/http2/LocalStrings.properties
index 485b234..3e114d8 100644
--- a/java/org/apache/coyote/http2/LocalStrings.properties
+++ b/java/org/apache/coyote/http2/LocalStrings.properties
@@ -35,11 +35,16 @@ hpack.invalidCharacter=The Unicode character [{0}] at code point [{1}] cannot be
 
 hpackEncoder.encodeHeader=Encoding header [{0}] with value [{1}]
 
+hpackdecoder.addDynamic=Adding header to index [{0}] of dynamic table with name [{1}] and value [{2}]
+hpackdecoder.clearDynamic=Emptying dynamic table
+hpackdecoder.emitHeader=Emitting header with name [{0}] and value [{1}]
 hpackdecoder.headerTableIndexInvalid=The header table index [{0}] is not valid as there are [{1}] static entries and [{2}] dynamic entries
 hpackdecoder.maxMemorySizeExceeded=The header table size [{0}] exceeds the maximum size [{1}]
 hpackdecoder.notImplemented=Not yet implemented
 hpackdecoder.nullHeader=Null header at index [{0}]
 hpackdecoder.tableSizeUpdateNotAtStart=Any table size update must be sent at the start of a header block
+hpackdecoder.useDynamic=Using header from index [{0}] of dynamic table
+hpackdecoder.useStatic=Using header from index [{0}] of static table
 hpackdecoder.zeroNotValidHeaderTableIndex=Zero is not a valid header table index
 
 hpackhuffman.huffmanEncodedHpackValueDidNotEndWithEOS=Huffman encoded value in HPACK headers did not end with EOS padding
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index dba11e9..8490f71 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -183,6 +183,9 @@
         Submitted by Thomas, and verified the fix is present in the donated
         hpack code in a further update. (remm)
       </fix>
+      <add>
+        Add debug logging for HTTP/2 HPACK header decoding. (markt)
+      </add>
     </changelog>
   </subsection>
   <subsection name="Jasper">

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org