@@ -227,12 +227,17 @@ class RemapRegex
227227 return _lowercase_substitutions;
228228 }
229229 inline bool
230- has_strategy () const
230+ has_strategy_option () const
231231 {
232232 return _has_strategy;
233233 }
234234 inline std::string const &
235- strategy () const
235+ strategy_name_option () const
236+ {
237+ return _strategy_name;
238+ }
239+ inline void const *
240+ strategy_option () const
236241 {
237242 return _strategy;
238243 }
@@ -274,7 +279,8 @@ class RemapRegex
274279 int _dns_timeout = -1 ;
275280
276281 bool _has_strategy = false ;
277- std::string _strategy = {};
282+ std::string _strategy_name = {};
283+ void const *_strategy = nullptr ;
278284
279285 Override *_first_override = nullptr ;
280286 int _sub_pos[MAX_SUBS];
@@ -323,8 +329,15 @@ RemapRegex::initialize(const std::string ®, const std::string &sub, const std
323329 } else if (opt.compare (start, 23 , " lowercase_substitutions" ) == 0 ) {
324330 _lowercase_substitutions = true ;
325331 } else if (opt.compare (start, 8 , " strategy" ) == 0 ) {
326- _has_strategy = true ;
327- _strategy = opt_val;
332+ _has_strategy = true ;
333+ _strategy_name = opt_val;
334+ if (!_strategy_name.empty () && " null" != _strategy_name) {
335+ _strategy = TSHttpInitNextHopNamedStrategyGet (_strategy_name.c_str ());
336+ if (nullptr == _strategy) {
337+ TSError (" [%s] Unable to resolve strategy: '%s'" , PLUGIN_NAME, opt_val.c_str ());
338+ _has_strategy = false ; // disable the strategy action
339+ }
340+ }
328341 } else if (opt_val.size () <= 0 ) {
329342 // All other options have a required value
330343 TSError (" [%s] Malformed options: %s" , PLUGIN_NAME, opt.c_str ());
@@ -987,20 +1000,14 @@ TSRemapDoRemap(void *ih, TSHttpTxn txnp, TSRemapRequestInfo *rri)
9871000 Dbg (dbg_ctl, " Setting DNS timeout to %d" , re->dns_timeout_option ());
9881001 TSHttpTxnDNSTimeoutSet (txnp, re->dns_timeout_option ());
9891002 }
990- if (re->has_strategy ()) {
991- auto const & strat = re->strategy ();
992- if (strat. empty () || " null " == strat) {
1003+ if (re->has_strategy_option ()) {
1004+ auto const strat = re->strategy_option ();
1005+ if (nullptr == strat) {
9931006 Dbg (dbg_ctl, " Clearing strategy (use parent.config)" );
994- TSHttpTxnNextHopStrategySet (txnp, nullptr );
9951007 } else {
996- void const *const stratptr = TSHttpTxnNextHopNamedStrategyGet (txnp, strat.c_str ());
997- if (nullptr == stratptr) {
998- Dbg (dbg_ctl, " No strategy found with name '%s'" , strat.c_str ());
999- } else {
1000- Dbg (dbg_ctl, " Setting strategy to %s" , strat.c_str ());
1001- TSHttpTxnNextHopStrategySet (txnp, stratptr);
1002- }
1008+ Dbg (dbg_ctl, " Setting strategy to %s" , re->strategy_name_option ().c_str ());
10031009 }
1010+ TSHttpTxnNextHopStrategySet (txnp, strat);
10041011 }
10051012 bool lowercase_substitutions = false ;
10061013 if (re->lowercase_substitutions_option () == true ) {
0 commit comments