traeak commented on code in PR #12593:
URL: https://github.com/apache/trafficserver/pull/12593#discussion_r4168383300


##########
plugins/header_rewrite/operators.cc:
##########
@@ -1645,45 +1645,48 @@ void
 OperatorSetNextHopStrategy::initialize(Parser &p)
 {
   Operator::initialize(p);
+  _stratname = p.get_arg();
 
-  _value.set_value(p.get_arg(), this);
-  Dbg(pi_dbg_ctl, "OperatorSetNextHopStrategy::initialie: %s", 
_value.get_value().c_str());
+  if (_stratname.empty() || "null" == _stratname) {
+    Dbg(pi_dbg_ctl, "OperatorSetNextHopStrategy() 'clear'");
+  } else {
+    _strategy = TSRemapNextHopStrategyFind(_stratname.c_str());
+    if (nullptr == _strategy) {
+      TSError("[%s] Failed to get strategy '%s'", PLUGIN_NAME, 
_stratname.c_str());
+      _apply = false;
+    } else {
+      Dbg(pi_dbg_ctl, "OperatorSetNextHopStrategy() '%s'", _stratname.c_str());
+    }
+  }
 }
 
 void
 OperatorSetNextHopStrategy::initialize_hooks()
 {
-  add_allowed_hook(TS_HTTP_READ_REQUEST_HDR_HOOK);
   add_allowed_hook(TS_REMAP_PSEUDO_HOOK);
 }
 
 bool
 OperatorSetNextHopStrategy::exec(const Resources &res) const
 {
-  if (!res.state.txnp) {
-    TSError("[%s] OperatorSetNextHopStrategy() failed. Transaction is null", 
PLUGIN_NAME);
+  if (!_apply) {
+    Dbg(pi_dbg_ctl, "OperatorSetNextHopStrategy::exec: do nothing");
+    return true;
   }
-
   auto const txnp = res.state.txnp;
-
-  std::string value;
-  _value.append_value(value, res);
-
-  // Setting an empty strategy clears it for either parent.config or remap to
-  if ("null" == value || value.empty()) {
-    Dbg(pi_dbg_ctl, "Clearing strategy");
-    TSHttpTxnNextHopStrategySet(txnp, nullptr);
-    return true;
+  if (!txnp) {
+    TSError("[%s] OperatorSetNextHopStrategy() failed. Transaction is null", 
PLUGIN_NAME);
+    return false;
   }
 
-  void const *const stratptr = TSHttpTxnNextHopNamedStrategyGet(txnp, 
value.c_str());
-  if (nullptr == stratptr) {
-    TSWarning("[%s] Failed to get strategy '%s'", PLUGIN_NAME, value.c_str());
+  if (nullptr == _strategy) {
+    Dbg(pi_dbg_ctl, "OperatorSetNextHopStrategy::exec: Clearing strategy");
   } else {
-    Dbg(pi_dbg_ctl, "   Setting strategy '%s'", value.c_str());
-    TSHttpTxnNextHopStrategySet(txnp, stratptr);
+    Dbg(pi_dbg_ctl, "OperatorSetNextHopStrategy::exec: Setting strategy to 
'%s'", _stratname.c_str());
   }
 
+  TSHttpTxnNextHopStrategySet(txnp, _strategy);
+
   return true;
 }

Review Comment:
   fixed



-- 
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]

Reply via email to