This is an automated email from the ASF dual-hosted git repository.

amc 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 816f0d4  Cleanup: This is just a stylistic cleanup of PR 4531. Mainly 
this is making the code more C++, removing a bit of duplication.
816f0d4 is described below

commit 816f0d43744542a9f4e37d521d06f37ed082aed7
Author: Alan M. Carroll <[email protected]>
AuthorDate: Thu Nov 29 18:02:43 2018 -0600

    Cleanup: This is just a stylistic cleanup of PR 4531.
    Mainly this is making the code more C++, removing a bit of duplication.
---
 proxy/http/remap/RemapPlugins.cc | 44 ++++++++++++++++------------------------
 proxy/http/remap/RemapPlugins.h  | 13 ++++--------
 2 files changed, 22 insertions(+), 35 deletions(-)

diff --git a/proxy/http/remap/RemapPlugins.cc b/proxy/http/remap/RemapPlugins.cc
index 198f85d..cd71cb7 100644
--- a/proxy/http/remap/RemapPlugins.cc
+++ b/proxy/http/remap/RemapPlugins.cc
@@ -84,7 +84,7 @@ RemapPlugins::run_single_remap()
   url_mapping *map             = _s->url_map.getMapping();
   remap_plugin_info *plugin    = map->get_plugin(_cur); // get the nth plugin 
in our list of plugins
   TSRemapStatus plugin_retcode = TSREMAP_NO_REMAP;
-
+  int zret                     = 1;
   Debug("url_rewrite", "running single remap rule id %d for the %d%s time", 
map->map_id, _cur,
         _cur == 1 ? "st" : _cur == 2 ? "nd" : _cur == 3 ? "rd" : "th");
 
@@ -94,38 +94,30 @@ RemapPlugins::run_single_remap()
     plugin_retcode = run_plugin(plugin);
   }
 
-  _cur++;
-
-  // If the plugin redirected, we need to end the remap chain now.
-  if (_s->remap_redirect) {
-    return 1;
-  }
+  ++_cur;
 
-  if (TSREMAP_DID_REMAP_STOP == plugin_retcode || TSREMAP_DID_REMAP == 
plugin_retcode) {
-    _rewriten++;
-  }
+  // If the plugin redirected, we need to end the remap chain now. Otherwise 
see what's next.
+  if (!_s->remap_redirect) {
+    if (TSREMAP_DID_REMAP_STOP == plugin_retcode || TSREMAP_DID_REMAP == 
plugin_retcode) {
+      ++_rewritten;
+    }
 
-  if (TSREMAP_NO_REMAP_STOP == plugin_retcode || TSREMAP_DID_REMAP_STOP == 
plugin_retcode) {
-    if (_rewriten == 0) {
-      Debug("url_rewrite", "plugin did not change host, port or path, copying 
from mapping rule");
-      url_rewrite_remap_request(_s->url_map, _request_url, 
_s->hdr_info.client_request.method_get_wksidx());
+    if (TSREMAP_NO_REMAP_STOP == plugin_retcode || TSREMAP_DID_REMAP_STOP == 
plugin_retcode) {
+      Debug("url_rewrite", "breaking remap plugin chain since last plugin said 
we should stop after %d rewrites", _rewritten);
+    } else if (_cur >= map->plugin_count()) {
+      Debug("url_rewrite", "completed all remap plugins for rule id %d, 
changed by %d plugins", map->map_id, _rewritten);
+    } else {
+      Debug("url_rewrite", "completed single remap, attempting another via 
immediate callback");
+      zret = 0; // not done yet.
     }
-    Debug("url_rewrite", "breaking remap plugin chain since last plugin said 
we should stop");
-    return 1;
-  }
 
-  if (_cur >= map->plugin_count()) {
-    if (_rewriten == 0) {
-      Debug("url_rewrite", "plugin did not change host, port or path, copying 
from mapping rule");
+    // If the chain is finished, and the URL hasn't been rewritten, do the 
rule remap.
+    if (zret && 0 == _rewritten) {
+      Debug("url_rewrite", "plugins did not change host, port or path, copying 
from mapping rule");
       url_rewrite_remap_request(_s->url_map, _request_url, 
_s->hdr_info.client_request.method_get_wksidx());
     }
-    // Normally, we would callback into this function but we dont have 
anything more to do!
-    Debug("url_rewrite", "completed all remap plugins for rule id %d", 
map->map_id);
-    return 1;
   }
-
-  Debug("url_rewrite", "completed single remap, attempting another via 
immediate callback");
-  return 0;
+  return zret;
 }
 
 int
diff --git a/proxy/http/remap/RemapPlugins.h b/proxy/http/remap/RemapPlugins.h
index ed7d55d..fad4097 100644
--- a/proxy/http/remap/RemapPlugins.h
+++ b/proxy/http/remap/RemapPlugins.h
@@ -38,17 +38,12 @@
  * A class that represents a queue of plugins to run
  **/
 struct RemapPlugins : public Continuation {
-  RemapPlugins() : _cur(0), _rewriten(0) {}
+  RemapPlugins() = default;
   RemapPlugins(HttpTransact::State *s, URL *u, HTTPHdr *h, host_hdr_info *hi)
-    : _cur(0), _rewriten(0), _s(s), _request_url(u), _request_header(h), 
_hh_ptr(hi)
+    : _s(s), _request_url(u), _request_header(h), _hh_ptr(hi)
   {
   }
 
-  ~RemapPlugins() override
-  {
-    _cur      = 0;
-    _rewriten = 0;
-  }
   // Some basic setters
   void
   setState(HttpTransact::State *state)
@@ -78,8 +73,8 @@ struct RemapPlugins : public Continuation {
   Action action;
 
 private:
-  unsigned int _cur        = 0;
-  unsigned int _rewriten   = 0;
+  unsigned _cur            = 0;
+  unsigned _rewritten      = 0;
   HttpTransact::State *_s  = nullptr;
   URL *_request_url        = nullptr;
   HTTPHdr *_request_header = nullptr;

Reply via email to