This is an automated email from the ASF dual-hosted git repository.
bcall 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 fc785d3 rewrite url after running all remap plugins
fc785d3 is described below
commit fc785d39450d3846d3928fb099b021b230a2d2af
Author: Takuya Kitano <[email protected]>
AuthorDate: Thu Nov 1 14:10:14 2018 +0900
rewrite url after running all remap plugins
---
proxy/http/remap/RemapPlugins.cc | 20 ++++++++++----------
proxy/http/remap/RemapPlugins.h | 11 ++++++++---
2 files changed, 18 insertions(+), 13 deletions(-)
diff --git a/proxy/http/remap/RemapPlugins.cc b/proxy/http/remap/RemapPlugins.cc
index ebddec2..198f85d 100644
--- a/proxy/http/remap/RemapPlugins.cc
+++ b/proxy/http/remap/RemapPlugins.cc
@@ -101,24 +101,24 @@ RemapPlugins::run_single_remap()
return 1;
}
- if (TSREMAP_NO_REMAP == plugin_retcode || TSREMAP_NO_REMAP_STOP ==
plugin_retcode) {
- // After running the first plugin, rewrite the request URL. This is doing
the default rewrite rule
- // to handle the case where no plugin ever rewrites.
- //
- // XXX we could probably optimize this a bit more by keeping a flag and
only rewriting the request URL
- // if no plugin has rewritten it already.
- if (_cur == 1) {
- 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_DID_REMAP_STOP == plugin_retcode || TSREMAP_DID_REMAP ==
plugin_retcode) {
+ _rewriten++;
}
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());
+ }
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");
+ 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;
diff --git a/proxy/http/remap/RemapPlugins.h b/proxy/http/remap/RemapPlugins.h
index bd76477..ed7d55d 100644
--- a/proxy/http/remap/RemapPlugins.h
+++ b/proxy/http/remap/RemapPlugins.h
@@ -38,13 +38,17 @@
* A class that represents a queue of plugins to run
**/
struct RemapPlugins : public Continuation {
- RemapPlugins() : _cur(0) {}
+ RemapPlugins() : _cur(0), _rewriten(0) {}
RemapPlugins(HttpTransact::State *s, URL *u, HTTPHdr *h, host_hdr_info *hi)
- : _cur(0), _s(s), _request_url(u), _request_header(h), _hh_ptr(hi)
+ : _cur(0), _rewriten(0), _s(s), _request_url(u), _request_header(h),
_hh_ptr(hi)
{
}
- ~RemapPlugins() override { _cur = 0; }
+ ~RemapPlugins() override
+ {
+ _cur = 0;
+ _rewriten = 0;
+ }
// Some basic setters
void
setState(HttpTransact::State *state)
@@ -75,6 +79,7 @@ struct RemapPlugins : public Continuation {
private:
unsigned int _cur = 0;
+ unsigned int _rewriten = 0;
HttpTransact::State *_s = nullptr;
URL *_request_url = nullptr;
HTTPHdr *_request_header = nullptr;