This is an automated email from the ASF dual-hosted git repository.
maskit pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new 534475f5b4 header_rewrite: Fix a bug that parameters on remap rules
are overwritten by subsequent rules (#12530)
534475f5b4 is described below
commit 534475f5b4f6278bc8981ff7965ee382b0ccf644
Author: Masakazu Kitajo <[email protected]>
AuthorDate: Mon Sep 29 13:48:52 2025 -0600
header_rewrite: Fix a bug that parameters on remap rules are overwritten by
subsequent rules (#12530)
---
plugins/header_rewrite/header_rewrite.cc | 71 +++++++++++++++++++-------------
1 file changed, 43 insertions(+), 28 deletions(-)
diff --git a/plugins/header_rewrite/header_rewrite.cc
b/plugins/header_rewrite/header_rewrite.cc
index 41deb18f75..c3545dd8e2 100644
--- a/plugins/header_rewrite/header_rewrite.cc
+++ b/plugins/header_rewrite/header_rewrite.cc
@@ -42,10 +42,6 @@ namespace header_rewrite_ns
{
std::once_flag initHRWLibs;
PluginFactory plugin_factory;
-
-int timezone = 0;
-int inboundIpSource = 0;
-
} // namespace header_rewrite_ns
static void
@@ -74,7 +70,7 @@ static int cont_rewrite_headers(TSCont, TSEvent, void *);
class RulesConfig
{
public:
- RulesConfig()
+ RulesConfig(int timezone, int inboundIpSource) : _timezone(timezone),
_inboundIpSource(inboundIpSource)
{
Dbg(dbg_ctl, "RulesConfig CTOR");
_cont = TSContCreate(cont_rewrite_headers, nullptr);
@@ -105,6 +101,18 @@ public:
return _rules[hook].get();
}
+ [[nodiscard]] int
+ timezone() const
+ {
+ return _timezone;
+ }
+
+ [[nodiscard]] int
+ inboundIpSource() const
+ {
+ return _inboundIpSource;
+ }
+
bool parse_config(const std::string &fname, TSHttpHookID default_hook, char
*from_url = nullptr, char *to_url = nullptr);
private:
@@ -113,6 +121,9 @@ private:
TSCont _cont;
std::array<std::unique_ptr<RuleSet>, TS_HTTP_LAST_HOOK + 1> _rules{};
std::array<ResourceIDs, TS_HTTP_LAST_HOOK + 1> _resids{};
+
+ int _timezone = 0;
+ int _inboundIpSource = 0;
};
void
@@ -331,16 +342,16 @@ RulesConfig::parse_config(const std::string &fname,
TSHttpHookID default_hook, c
}
static void
-setPluginControlValues(TSHttpTxn txnp)
+setPluginControlValues(TSHttpTxn txnp, RulesConfig *conf)
{
- if (header_rewrite_ns::timezone != 0 || header_rewrite_ns::inboundIpSource
!= 0) {
+ if (conf->timezone() != 0 || conf->inboundIpSource() != 0) {
ConditionNow temporal_statement; // This could be any statement that use
the private slot.
int slot = temporal_statement.get_txn_private_slot();
PrivateSlotData private_data;
private_data.raw = reinterpret_cast<uint64_t>(TSUserArgGet(txnp,
slot));
- private_data.timezone = header_rewrite_ns::timezone;
- private_data.ip_source = header_rewrite_ns::inboundIpSource;
+ private_data.timezone = conf->timezone();
+ private_data.ip_source = conf->inboundIpSource();
TSUserArgSet(txnp, slot, reinterpret_cast<void *>(private_data.raw));
}
}
@@ -373,7 +384,7 @@ cont_rewrite_headers(TSCont contp, TSEvent event, void
*edata)
break;
case TS_EVENT_HTTP_TXN_START:
hook = TS_HTTP_TXN_START_HOOK;
- setPluginControlValues(txnp);
+ setPluginControlValues(txnp, conf);
break;
case TS_EVENT_HTTP_TXN_CLOSE:
hook = TS_HTTP_TXN_CLOSE_HOOK;
@@ -441,6 +452,8 @@ TSPluginInit(int argc, const char *argv[])
}
std::string geoDBpath;
+ int inboundIpSource = 0;
+ int timezone = 0;
while (true) {
int opt = getopt_long(argc, const_cast<char *const *>(argv), "m:t:i:",
longopt, nullptr);
@@ -449,23 +462,23 @@ TSPluginInit(int argc, const char *argv[])
geoDBpath = optarg;
break;
case 't':
- Dbg(pi_dbg_ctl, "Global timezone %s", optarg);
+ Dbg(pi_dbg_ctl, "Default timezone %s", optarg);
if (strcmp(optarg, "LOCAL") == 0) {
- header_rewrite_ns::timezone = TIMEZONE_LOCAL;
+ timezone = TIMEZONE_LOCAL;
} else if (strcmp(optarg, "GMT") == 0) {
- header_rewrite_ns::timezone = TIMEZONE_GMT;
+ timezone = TIMEZONE_GMT;
} else {
TSError("[%s] Unknown value for timezone parameter: %s", PLUGIN_NAME,
optarg);
}
break;
case 'i':
- Dbg(pi_dbg_ctl, "Global inbound IP source %s", optarg);
+ Dbg(pi_dbg_ctl, "Default inbound IP source %s", optarg);
if (strcmp(optarg, "PEER") == 0) {
- header_rewrite_ns::inboundIpSource = IP_SRC_PEER;
+ inboundIpSource = IP_SRC_PEER;
} else if (strcmp(optarg, "PROXY") == 0) {
- header_rewrite_ns::inboundIpSource = IP_SRC_PROXY;
+ inboundIpSource = IP_SRC_PROXY;
} else if (strcmp(optarg, "PLUGIN") == 0) {
- header_rewrite_ns::inboundIpSource = IP_SRC_PLUGIN;
+ inboundIpSource = IP_SRC_PLUGIN;
} else {
TSError("[%s] Unknown value for inbound-ip-source parameter: %s",
PLUGIN_NAME, optarg);
}
@@ -487,7 +500,7 @@ TSPluginInit(int argc, const char *argv[])
// Parse the global config file(s). All rules are just appended
// to the "global" Rules configuration.
- auto *conf = new RulesConfig;
+ auto *conf = new RulesConfig(timezone, inboundIpSource);
bool got_config = false;
for (int i = optind; i < argc; ++i) {
@@ -553,6 +566,8 @@ TSRemapNewInstance(int argc, char *argv[], void **ih, char
* /* errbuf ATS_UNUSE
++argv;
std::string geoDBpath;
+ int timezone = 0;
+ int inboundIpSource = 0;
while (true) {
int opt = getopt_long(argc, (char *const *)argv, "m:t:i:", longopt,
nullptr);
@@ -561,23 +576,23 @@ TSRemapNewInstance(int argc, char *argv[], void **ih,
char * /* errbuf ATS_UNUSE
geoDBpath = optarg;
break;
case 't':
- Dbg(pi_dbg_ctl, "Global timezone %s", optarg);
+ Dbg(pi_dbg_ctl, "Default timezone %s", optarg);
if (strcmp(optarg, "LOCAL") == 0) {
- header_rewrite_ns::timezone = TIMEZONE_LOCAL;
+ timezone = TIMEZONE_LOCAL;
} else if (strcmp(optarg, "GMT") == 0) {
- header_rewrite_ns::timezone = TIMEZONE_GMT;
+ timezone = TIMEZONE_GMT;
} else {
TSError("[%s] Unknown value for timezone parameter: %s", PLUGIN_NAME,
optarg);
}
break;
case 'i':
- Dbg(pi_dbg_ctl, "Global inbound IP source %s", optarg);
+ Dbg(pi_dbg_ctl, "Default inbound IP source %s", optarg);
if (strcmp(optarg, "PEER") == 0) {
- header_rewrite_ns::inboundIpSource = IP_SRC_PEER;
+ inboundIpSource = IP_SRC_PEER;
} else if (strcmp(optarg, "PROXY") == 0) {
- header_rewrite_ns::inboundIpSource = IP_SRC_PROXY;
+ inboundIpSource = IP_SRC_PROXY;
} else if (strcmp(optarg, "PLUGIN") == 0) {
- header_rewrite_ns::inboundIpSource = IP_SRC_PLUGIN;
+ inboundIpSource = IP_SRC_PLUGIN;
} else {
TSError("[%s] Unknown value for inbound-ip-source parameter: %s",
PLUGIN_NAME, optarg);
}
@@ -598,7 +613,7 @@ TSRemapNewInstance(int argc, char *argv[], void **ih, char
* /* errbuf ATS_UNUSE
std::call_once(initHRWLibs, [&geoDBpath]() { initHRWLibraries(geoDBpath);
});
}
- auto *conf = new RulesConfig;
+ auto *conf = new RulesConfig(timezone, inboundIpSource);
for (int i = optind; i < argc; ++i) {
Dbg(pi_dbg_ctl, "Loading remap configuration file %s", argv[i]);
@@ -635,11 +650,11 @@ TSRemapDoRemap(void *ih, TSHttpTxn rh, TSRemapRequestInfo
*rri)
return TSREMAP_NO_REMAP;
}
- setPluginControlValues(rh);
-
TSRemapStatus rval = TSREMAP_NO_REMAP;
auto *conf = static_cast<RulesConfig *>(ih);
+ setPluginControlValues(rh, conf);
+
// Go through all hooks we support, and setup the txn hook(s) as necessary
for (int i = TS_HTTP_READ_REQUEST_HDR_HOOK; i < TS_HTTP_LAST_HOOK; ++i) {
if (conf->rule(i)) {