zwoop commented on code in PR #13587:
URL: https://github.com/apache/trafficserver/pull/13587#discussion_r4232597847
##########
plugins/header_rewrite/condition.cc:
##########
@@ -19,6 +19,7 @@
// condition.cc: Implementation of the condition base class
//
//
+#include <charconv>
#include <string>
Review Comment:
`from_chars_result::ec` is a `std::errc`, so `<charconv>` has to provide the
type, and ATS relies on that elsewhere (`cidr.h` in this plugin, `InkAPI.cc`,
`MIME.cc`, `HTTP.cc`). Leaving it.
##########
tools/hrw4u/src/common.py:
##########
@@ -43,20 +43,57 @@ class RegexPatterns:
SUBSTITUTE_PATTERN: Final = re.compile(
r"""(?P<escaped>\{\{.*?\}\})
|
-
(?<!%)\{\s*(?P<func>[a-zA-Z_][a-zA-Z0-9_-]*)\s*\((?P<args>[^)]*)\)\s*\}
+ (?<!%)\{\s*(?P<func>[a-zA-Z_][a-zA-Z0-9_-]*)\s*\((?P<args>[^)]*)\)
+ (?:\s+with\s+(?P<func_mods>[A-Za-z][A-Za-z0-9,\s]*?))?\s*\}
|
(?<!%)\{(?P<var>[^{}()]+)\}
""",
re.VERBOSE | re.DOTALL,
)
+ # An interpolated symbol may carry modifiers, spelled as on a condition:
{inbound.url.path with NORM}
+ INTERPOLATION_MODS: Final =
re.compile(r'^\s*(?P<name>\S+?)\s+with\s+(?P<mods>[A-Za-z][A-Za-z0-9,\s]*?)\s*$')
+
+ # Trailing [MODS] inside a %{} block, which u4wrh turns back into a "with"
clause
+ PERCENT_MODS: Final =
re.compile(r'^(?P<body>.*?)\s+\[(?P<mods>[A-Za-z][A-Za-z0-9,\s]*)\]$')
+
# Additional performance patterns
IDENTIFIER: Final = re.compile(r'^[a-zA-Z_][a-zA-Z0-9_]*$')
WHITESPACE: Final = re.compile(r'\s+')
COMMENT_BLOCK: Final = re.compile(r'/\*.*?\*/', re.DOTALL)
STRING_INTERPOLATION: Final =
re.compile(r'\{([a-zA-Z_][a-zA-Z0-9_.-]*(?:\([^)]*\))?)\}', re.MULTILINE)
+def parse_mods(raw: str | None) -> list[str]:
+ """Parse 'MOD, mod,NOCASE' into ['MOD', 'NOCASE']; a repeat would fail
header_rewrite's modifier check."""
Review Comment:
Reworded in 5daff23b5d: repeats are dropped because header_rewrite would
reject them.
##########
tools/hrw4u/src/hrw_symbols.py:
##########
@@ -413,7 +414,21 @@ def negate_expression(self, term: str) -> str:
return f"!({t})"
def percent_to_ident_or_func(self, percent: str, section: SectionType |
None) -> tuple[str, bool]:
- """Convert percent block to identifier or function call."""
+ """Convert a %{} block to an identifier or function call; trailing
[MODS] become a "with" clause."""
+ stripped, mods = split_percent_mods(percent)
+ expr, is_func = self._percent_to_ident_or_func(stripped, section)
+
+ if not mods:
+ return expr, is_func
+
+ # A block with no DSL equivalent comes back as %{...}, where the
modifiers belong
+ # inside the braces rather than in a "with" clause.
+ if expr == stripped:
+ return apply_percent_mods(expr, mods), is_func
+
+ return f"{expr} with {','.join(mods)}", is_func
+
Review Comment:
NORM is the only modifier valid on a value (`VALUE_MODIFIERS`), and hrw4u
rejects any other in an interpolation, so there's never more than one to order.
Leaving it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]