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

cmcfarlen pushed a commit to branch 10.2.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git

commit 918448fcc91f56cf4e479aed9970c91e324e1d21
Author: Leif Hedstrom <[email protected]>
AuthorDate: Thu Apr 9 11:14:51 2026 -0600

    hrw4u: Fix u4wrh HEADER value resolution missing section context (#13068)
    
    * hrw4u: Fix u4wrh HEADER value resolution missing section context
    
    _handle_set_rm_operation was passing None as the section to
    _rewrite_inline_percents, causing %{HEADER:...} in operator
    values to always resolve to the default inbound.resp. prefix
    instead of the correct context-dependent prefix.
    
    * Address Copilot's review
    
    (cherry picked from commit ebb5e3474d403c24e47fb32f5de78fa4ae12699a)
---
 tools/hrw4u/src/hrw_symbols.py                             |  7 ++++---
 tools/hrw4u/tests/data/ops/exceptions.txt                  |  2 ++
 tools/hrw4u/tests/data/ops/explicit_header_value.ast.txt   |  1 +
 tools/hrw4u/tests/data/ops/explicit_header_value.input.txt | 14 ++++++++++++++
 .../hrw4u/tests/data/ops/explicit_header_value.output.txt  | 11 +++++++++++
 tools/hrw4u/tests/data/ops/header_value_context.input.txt  | 14 ++++++++++++++
 tools/hrw4u/tests/data/ops/header_value_context.output.txt | 11 +++++++++++
 7 files changed, 57 insertions(+), 3 deletions(-)

diff --git a/tools/hrw4u/src/hrw_symbols.py b/tools/hrw4u/src/hrw_symbols.py
index aa7ef58d4d..0a0339b2d0 100644
--- a/tools/hrw4u/src/hrw_symbols.py
+++ b/tools/hrw4u/src/hrw_symbols.py
@@ -231,13 +231,14 @@ class InverseSymbolResolver(SymbolResolverBase):
 
         return repl
 
-    def _handle_set_rm_operation(self, cmd: str, toks: list[str], prefix: str, 
qualifier: str, context: str) -> str:
+    def _handle_set_rm_operation(
+            self, cmd: str, toks: list[str], prefix: str, qualifier: str, 
section: SectionType | None = None) -> str:
         if cmd.startswith("rm-"):
             return f'{prefix}{qualifier} = ""'
         if len(toks) < 3:
             raise SymbolResolutionError(" ".join(toks), f"Missing value for 
{cmd}")
         value = " ".join(toks[2:])
-        value = self._rewrite_inline_percents(value, None)
+        value = self._rewrite_inline_percents(value, section)
         return f"{prefix}{qualifier} = {value}"
 
     def _handle_operator_command(
@@ -260,7 +261,7 @@ class InverseSymbolResolver(SymbolResolverBase):
             prefix = self.get_prefix_for_context(context_type, section)
 
             processed_qualifier = qualifier_processor(qualifier)
-            return self._handle_set_rm_operation(cmd, toks, prefix, 
processed_qualifier, op_context)
+            return self._handle_set_rm_operation(cmd, toks, prefix, 
processed_qualifier, section)
 
         if lhs_key.endswith("."):
             if len(toks) < 2:
diff --git a/tools/hrw4u/tests/data/ops/exceptions.txt 
b/tools/hrw4u/tests/data/ops/exceptions.txt
index 9628625f81..d954a6ae38 100644
--- a/tools/hrw4u/tests/data/ops/exceptions.txt
+++ b/tools/hrw4u/tests/data/ops/exceptions.txt
@@ -3,5 +3,7 @@
 
 # QSA (Query String Append) is a reverse-only test
 qsa.input: u4wrh
+# HEADER value context is reverse-only (forward uses explicit SERVER-HEADER)
+header_value_context.input: u4wrh
 # HTTP-CNTL valid bools can not reverse back to the original input
 http_cntl_valid_bools.input: hrw4u
diff --git a/tools/hrw4u/tests/data/ops/explicit_header_value.ast.txt 
b/tools/hrw4u/tests/data/ops/explicit_header_value.ast.txt
new file mode 100644
index 0000000000..347f6ae3f7
--- /dev/null
+++ b/tools/hrw4u/tests/data/ops/explicit_header_value.ast.txt
@@ -0,0 +1 @@
+(program (programItem (section SEND_REQUEST { (sectionBody (statement 
outbound.req.X-From-Client = (value "{inbound.req.X-Source}") ;)) (sectionBody 
(statement outbound.req.X-From-Server = (value "{outbound.req.X-Source}") ;)) 
})) (programItem (section READ_RESPONSE { (sectionBody (statement 
outbound.resp.X-From-Client = (value "{inbound.req.X-Source}") ;)) (sectionBody 
(statement outbound.resp.X-From-Server = (value "{outbound.req.X-Source}") ;)) 
})) (programItem (section SEND_RESPONSE  [...]
diff --git a/tools/hrw4u/tests/data/ops/explicit_header_value.input.txt 
b/tools/hrw4u/tests/data/ops/explicit_header_value.input.txt
new file mode 100644
index 0000000000..800f8af3be
--- /dev/null
+++ b/tools/hrw4u/tests/data/ops/explicit_header_value.input.txt
@@ -0,0 +1,14 @@
+SEND_REQUEST {
+    outbound.req.X-From-Client = "{inbound.req.X-Source}";
+    outbound.req.X-From-Server = "{outbound.req.X-Source}";
+}
+
+READ_RESPONSE {
+    outbound.resp.X-From-Client = "{inbound.req.X-Source}";
+    outbound.resp.X-From-Server = "{outbound.req.X-Source}";
+}
+
+SEND_RESPONSE {
+    inbound.resp.X-From-Client = "{inbound.req.X-Source}";
+    inbound.resp.X-From-Server = "{outbound.req.X-Source}";
+}
diff --git a/tools/hrw4u/tests/data/ops/explicit_header_value.output.txt 
b/tools/hrw4u/tests/data/ops/explicit_header_value.output.txt
new file mode 100644
index 0000000000..68a7572695
--- /dev/null
+++ b/tools/hrw4u/tests/data/ops/explicit_header_value.output.txt
@@ -0,0 +1,11 @@
+cond %{SEND_REQUEST_HDR_HOOK} [AND]
+    set-header X-From-Client "%{CLIENT-HEADER:X-Source}"
+    set-header X-From-Server "%{SERVER-HEADER:X-Source}"
+
+cond %{READ_RESPONSE_HDR_HOOK} [AND]
+    set-header X-From-Client "%{CLIENT-HEADER:X-Source}"
+    set-header X-From-Server "%{SERVER-HEADER:X-Source}"
+
+cond %{SEND_RESPONSE_HDR_HOOK} [AND]
+    set-header X-From-Client "%{CLIENT-HEADER:X-Source}"
+    set-header X-From-Server "%{SERVER-HEADER:X-Source}"
diff --git a/tools/hrw4u/tests/data/ops/header_value_context.input.txt 
b/tools/hrw4u/tests/data/ops/header_value_context.input.txt
new file mode 100644
index 0000000000..bf8241008c
--- /dev/null
+++ b/tools/hrw4u/tests/data/ops/header_value_context.input.txt
@@ -0,0 +1,14 @@
+SEND_REQUEST {
+    outbound.req.X-Auth = "{outbound.req.X-Token}";
+    outbound.req.X-Info = "val={outbound.req.X-Detail}";
+}
+
+READ_RESPONSE {
+    outbound.resp.X-Auth = "{outbound.resp.X-Token}";
+    outbound.resp.X-Info = "val={outbound.resp.X-Detail}";
+}
+
+SEND_RESPONSE {
+    inbound.resp.X-Auth = "{inbound.resp.X-Token}";
+    inbound.resp.X-Info = "val={inbound.resp.X-Detail}";
+}
diff --git a/tools/hrw4u/tests/data/ops/header_value_context.output.txt 
b/tools/hrw4u/tests/data/ops/header_value_context.output.txt
new file mode 100644
index 0000000000..2983071f74
--- /dev/null
+++ b/tools/hrw4u/tests/data/ops/header_value_context.output.txt
@@ -0,0 +1,11 @@
+cond %{SEND_REQUEST_HDR_HOOK} [AND]
+    set-header X-Auth %{HEADER:X-Token}
+    set-header X-Info "val=%{HEADER:X-Detail}"
+
+cond %{READ_RESPONSE_HDR_HOOK} [AND]
+    set-header X-Auth %{HEADER:X-Token}
+    set-header X-Info "val=%{HEADER:X-Detail}"
+
+cond %{SEND_RESPONSE_HDR_HOOK} [AND]
+    set-header X-Auth %{HEADER:X-Token}
+    set-header X-Info "val=%{HEADER:X-Detail}"

Reply via email to