Repository: trafficserver
Updated Branches:
  refs/heads/master 64ff6709f -> 5701441b6


[TS-2631] header_rewrite to support new destinations in global plugin case


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/50a583f7
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/50a583f7
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/50a583f7

Branch: refs/heads/master
Commit: 50a583f7e4ef467b6c7f7af3fa6bb25ba4b0dfee
Parents: 64ff670
Author: Brian Geffon <[email protected]>
Authored: Wed Mar 12 14:13:21 2014 -0700
Committer: Brian Geffon <[email protected]>
Committed: Wed Mar 12 14:13:21 2014 -0700

----------------------------------------------------------------------
 plugins/header_rewrite/operators.cc | 42 +++++++++++++++++++++-----------
 1 file changed, 28 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/50a583f7/plugins/header_rewrite/operators.cc
----------------------------------------------------------------------
diff --git a/plugins/header_rewrite/operators.cc 
b/plugins/header_rewrite/operators.cc
index 3b2cd27..086a316 100644
--- a/plugins/header_rewrite/operators.cc
+++ b/plugins/header_rewrite/operators.cc
@@ -144,7 +144,6 @@ OperatorSetStatusReason::exec(const Resources& res) const
 }
 
 
-/// TODO and XXX: These currently only support when running as remap plugin.
 // OperatorSetDestination
 void
 OperatorSetDestination::initialize(Parser& p)
@@ -153,16 +152,31 @@ OperatorSetDestination::initialize(Parser& p)
 
   _url_qual = parse_url_qualifier(p.get_arg());
   _value.set_value(p.get_value());
-  // TODO: What resources would we require here?
+  require_resources(RSRC_CLIENT_REQUEST_HEADERS);
+  require_resources(RSRC_SERVER_REQUEST_HEADERS);
 }
 
 
 void
 OperatorSetDestination::exec(const Resources& res) const
 {
-  if (res._rri) {
+  if (res._rri || (res.bufp && res.hdr_loc)) {
     std::string value;
 
+    // Determine which TSMBuffer and TSMLoc to use
+    TSMBuffer bufp;
+    TSMLoc url_m_loc;
+    if (res._rri) {
+      bufp = res._rri->requestBufp;
+      url_m_loc = res._rri->requestUrl;
+    } else {
+      bufp = res.bufp;
+      if (TSHttpHdrUrlGet(res.bufp, res.hdr_loc, &url_m_loc) != TS_SUCCESS) {
+        TSDebug(PLUGIN_NAME, "TSHttpHdrUrlGet was unable to return the url 
m_loc");
+        return;
+      }
+    }
+
     // Never set an empty destination value (I don't think that ever makes 
sense?)
     switch (_url_qual) {
 
@@ -172,8 +186,8 @@ OperatorSetDestination::exec(const Resources& res) const
         TSDebug(PLUGIN_NAME, "Would set destination HOST to an empty value, 
skipping");
       } else {
         const_cast<Resources&>(res).changed_url = true;
-        TSUrlHostSet(res._rri->requestBufp, res._rri->requestUrl, 
value.c_str(), value.size());
-        TSDebug(PLUGIN_NAME, "OperatorSetHost::exec() invoked with HOST: %s", 
value.c_str());
+        TSUrlHostSet(bufp, url_m_loc, value.c_str(), value.size());
+        TSDebug(PLUGIN_NAME, "OperatorSetDestination::exec() invoked with 
HOST: %s", value.c_str());
       }
       break;
 
@@ -183,8 +197,8 @@ OperatorSetDestination::exec(const Resources& res) const
         TSDebug(PLUGIN_NAME, "Would set destination PATH to an empty value, 
skipping");
       } else {
         const_cast<Resources&>(res).changed_url = true;
-        TSUrlPathSet(res._rri->requestBufp, res._rri->requestUrl, 
value.c_str(), value.size());
-        TSDebug(PLUGIN_NAME, "OperatorSetHost::exec() invoked with PATH: %s", 
value.c_str());
+        TSUrlPathSet(bufp, url_m_loc, value.c_str(), value.size());
+        TSDebug(PLUGIN_NAME, "OperatorSetDestination::exec() invoked with 
PATH: %s", value.c_str());
       }
       break;
 
@@ -196,7 +210,7 @@ OperatorSetDestination::exec(const Resources& res) const
         //1.6.4--Support for preserving QSA in case of set-destination
         if (get_oper_modifiers() & OPER_QSA) {
           int query_len = 0;
-          const char* query = TSUrlHttpQueryGet(res._rri->requestBufp, 
res._rri->requestUrl, &query_len);
+          const char* query = TSUrlHttpQueryGet(bufp, url_m_loc, &query_len);
           TSDebug(PLUGIN_NAME, "QSA mode, append original query string: %.*s", 
query_len, query);
           //std::string connector = (value.find("?") == std::string::npos)? 
"?" : "&";
           value.append("&");
@@ -204,18 +218,18 @@ OperatorSetDestination::exec(const Resources& res) const
         }
 
         const_cast<Resources&>(res).changed_url = true;
-        TSUrlHttpQuerySet(res._rri->requestBufp, res._rri->requestUrl, 
value.c_str(), value.size());
-        TSDebug(PLUGIN_NAME, "OperatorSetHost::exec() invoked with QUERY: %s", 
value.c_str());
+        TSUrlHttpQuerySet(bufp, url_m_loc, value.c_str(), value.size());
+        TSDebug(PLUGIN_NAME, "OperatorSetDestination::exec() invoked with 
QUERY: %s", value.c_str());
       }
       break;
 
     case URL_QUAL_PORT:
-      if (_value.get_int_value() <= 0) {
+      if (_value.get_int_value() <= 0 || _value.get_int_value() > 0xFFFF) {
         TSDebug(PLUGIN_NAME, "Would set destination PORT to an invalid range, 
skipping");
       } else {
         const_cast<Resources&>(res).changed_url = true;
-        TSUrlPortSet(res._rri->requestBufp, res._rri->requestUrl, 
_value.get_int_value());
-        TSDebug(PLUGIN_NAME, "OperatorSetHost::exec() invoked with PORT: %d", 
_value.get_int_value());
+        TSUrlPortSet(bufp, url_m_loc, _value.get_int_value());
+        TSDebug(PLUGIN_NAME, "OperatorSetDestination::exec() invoked with 
PORT: %d", _value.get_int_value());
       }
       break;
     case URL_QUAL_URL:
@@ -225,7 +239,7 @@ OperatorSetDestination::exec(const Resources& res) const
       break;
     }
   } else {
-    // TODO: Handle the non-remap case here (InkAPI hooks)
+    TSDebug(PLUGIN_NAME, "OperatorSetDestination::exec() unable to continue 
due to missing bufp=%p or hdr_loc=%p, rri=%p!", res.bufp, res.hdr_loc, 
res._rri);
   }
 }
 

Reply via email to