shukitchan commented on code in PR #11320:
URL: https://github.com/apache/trafficserver/pull/11320#discussion_r1591379690
##########
plugins/header_rewrite/operators.cc:
##########
@@ -1103,3 +1106,73 @@ OperatorSetHttpCntl::exec(const Resources &res) const
Dbg(pi_dbg_ctl, " Turning OFF %s for transaction",
HttpCntls[static_cast<size_t>(_cntl_qual)]);
}
}
+
+void
+OperatorRunPlugin::initialize(Parser &p)
+{
+ Operator::initialize(p);
+
+ auto plugin_name = p.get_arg();
+ auto plugin_args = p.get_value();
+
+ if (plugin_name.empty()) {
+ TSError("[%s] missing plugin name", PLUGIN_NAME);
+ return;
+ }
+
+ std::vector<std::string> tokens;
+ std::istringstream iss(plugin_args);
+ std::string token;
+
+ while (iss >> std::quoted(token)) {
+ tokens.push_back(token);
+ }
+
+ // Create argc and argv
+ int argc = tokens.size() + 2;
+ char **argv = new char *[argc];
+
+ argv[0] = p.from_url();
+ argv[1] = p.to_url();
+
+ for (int i = 0; i < argc; ++i) {
+ argv[i + 2] = const_cast<char *>(tokens[i].c_str());
+ }
+
+ std::string error;
+
+ // We have to escalate access while loading these plugins, just as done when
loading remap.config
+ {
+ uint32_t elevate_access = 0;
+
+ REC_ReadConfigInteger(elevate_access, "proxy.config.plugin.load_elevated");
+ ElevateAccess access(elevate_access ? ElevateAccess::FILE_PRIVILEGE : 0);
+
+ _plugin = plugin_factory.getRemapPlugin(swoc::file::path(plugin_name),
argc, const_cast<char **>(argv), error,
+ isPluginDynamicReloadEnabled());
+ } // done elevating access
+
+ delete[] argv;
+
+ if (!_plugin) {
+ TSError("[%s] Unable to load plugin '%s': %s", PLUGIN_NAME,
plugin_name.c_str(), error.c_str());
+ }
+}
+
+void
+OperatorRunPlugin::initialize_hooks()
+{
+ add_allowed_hook(TS_REMAP_PSEUDO_HOOK);
+
+ require_resources(RSRC_CLIENT_REQUEST_HEADERS); // Need this for the txnp
+}
+
+void
+OperatorRunPlugin::exec(const Resources &res) const
+{
+ TSReleaseAssert(_plugin != nullptr);
+
+ if (res._rri && res.txnp) {
+ _plugin->doRemap(res.txnp, res._rri);
Review Comment:
Just curious. should we pass on the return status of the doRemap() function
somewhere?
--
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]