You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by bc...@apache.org on 2015/05/12 00:53:40 UTC

[1/2] trafficserver git commit: TS-2609: Header rewrite plugin added *URL:HOST condition

Repository: trafficserver
Updated Branches:
  refs/heads/master 21cfb7bd1 -> a48c1c431


TS-2609: Header rewrite plugin added *URL:HOST condition


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

Branch: refs/heads/master
Commit: a67211bfcde01910dce104a531e38c62ffeb5896
Parents: 21cfb7b
Author: Bryan Call <bc...@apache.org>
Authored: Mon May 11 15:50:39 2015 -0700
Committer: Bryan Call <bc...@apache.org>
Committed: Mon May 11 15:52:19 2015 -0700

----------------------------------------------------------------------
 doc/reference/plugins/header_rewrite.en.rst | 22 ++++++--
 plugins/header_rewrite/conditions.cc        | 64 ++++++++++++++++++++++--
 plugins/header_rewrite/conditions.h         |  7 ++-
 plugins/header_rewrite/factory.cc           | 12 +++--
 4 files changed, 91 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/a67211bf/doc/reference/plugins/header_rewrite.en.rst
----------------------------------------------------------------------
diff --git a/doc/reference/plugins/header_rewrite.en.rst b/doc/reference/plugins/header_rewrite.en.rst
index f17a1a1..402ec2f 100644
--- a/doc/reference/plugins/header_rewrite.en.rst
+++ b/doc/reference/plugins/header_rewrite.en.rst
@@ -119,16 +119,17 @@ only be evaluated if the condition(s) are met::
   cond %{COOKIE:cookie-name} operand            [condition_flags]
   cond %{CLIENT-HEADER:header-name} operand     [condition_flags]
   cond %{PROTOCOL} operand                      [condition_flags]
-  cond %{HOST} operand                          [condition_flags]
-  cond %{TOHOST} operand                        [condition_flags]
-  cond %{FROMHOST} operand                      [condition_flags]
   cond %{PATH} operand                          [condition_flags]
   cond %{QUERY} operand                         [condition_flags]
   cond %{INTERNAL-TRANSACTION}                  [condition_flags]
   cond %{CLIENT-IP}                             [condition_flags]
   cond %{INCOMING-PORT}                         [condition_flags]
   cond %{METHOD}                                [condition_flags]
-
+  cond %{CLIENT-URL:option-name}                [condition_flags]
+  cond %{URL:option-name}                       [condition_flags]
+  cond %{FROM-URL:option-name}                  [condition_flags]
+  cond %{TO-URL:option-name}                    [condition_flags]
+  
 The difference between HEADER and CLIENT-HEADER is that HEADER adapts to the
 hook it's running in, whereas CLIENT-HEADER always applies to the client
 request header. The %{TRUE} condition is also the default condition if no
@@ -147,6 +148,19 @@ For remap.config plugin instanations, the default hook is named
 REMAP_PSEUDO_HOOK. This can be useful if you are mixing other hooks in a
 configuration, but being the default it is also optional.
 
+CLIENT-URL, URL, URL-FROM, and URL-TO
+-------------------------
+URL adapts to the hook it's running in and CLIENT-URL will always give you
+the client URL.  FROM-URL and TO-URL are from the remap rule that matched and
+can only be used if the plugin is a being run as a remap plugin.  An option
+is required to match that section of the URL.
+
+Supported Option Names:
+   HOST
+   
+Example:
+   cond %{URL:HOST} =www.example.com
+
 ---------------
 Condition flags
 ---------------

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/a67211bf/plugins/header_rewrite/conditions.cc
----------------------------------------------------------------------
diff --git a/plugins/header_rewrite/conditions.cc b/plugins/header_rewrite/conditions.cc
index cffd8f6..a031b1e 100644
--- a/plugins/header_rewrite/conditions.cc
+++ b/plugins/header_rewrite/conditions.cc
@@ -337,8 +337,13 @@ ConditionQuery::eval(const Resources &res)
 
 // ConditionUrl: request or response header. TODO: This is not finished, at all!!!
 void
-ConditionUrl::initialize(Parser & /* p ATS_UNUSED */)
+ConditionUrl::initialize(Parser &p)
 {
+  Condition::initialize(p);
+
+  Matchers<std::string> *match = new Matchers<std::string>(_cond_op);
+  match->set(p.get_arg());
+  _matcher = match;
 }
 
 
@@ -358,11 +363,62 @@ ConditionUrl::append_value(std::string & /* s ATS_UNUSED */, const Resources & /
 
 
 bool
-ConditionUrl::eval(const Resources & /* res ATS_UNUSED */)
+ConditionUrl::eval(const Resources &res)
 {
-  bool ret = false;
+  TSDebug(PLUGIN_NAME, "ConditionUrl::eval");
+  TSMLoc url = NULL;
+  TSMBuffer bufp = NULL;
+  std::string s;
 
-  return ret;
+  TSDebug(PLUGIN_NAME, "res.bufp %p res.client_bufp: %p res._rri->requestBufp: %p", res.bufp, res.client_bufp,
+          res._rri->requestBufp);
+  if (res._rri != NULL) {
+    // called at the remap hook
+    bufp = res._rri->requestBufp;
+    if (_type == URL || _type == CLIENT) {
+      // res._rri->requestBufp and res.client_bufp are the same if it is at the remap hook
+      TSDebug(PLUGIN_NAME, "   Using the request url");
+      url = res._rri->requestUrl;
+      TSMLoc tmp_url = NULL;
+      TSHttpHdrUrlGet(res.client_bufp, res.client_hdr_loc, &tmp_url);
+      assert(tmp_url == url);
+      TSDebug(PLUGIN_NAME, "url %p tmp_url: %p", url, tmp_url);
+    } else if (_type == FROM) {
+      TSDebug(PLUGIN_NAME, "   Using the from url");
+      url = res._rri->mapFromUrl;
+    } else if (_type == TO) {
+      TSDebug(PLUGIN_NAME, "   Using the to url");
+      url = res._rri->mapToUrl;
+    } else {
+      TSError("header_rewrite: Invalid option value");
+      return false;
+    }
+  } else {
+    TSMLoc hdr_loc = NULL;
+    if (_type == CLIENT) {
+      bufp = res.client_bufp;
+      hdr_loc = res.client_hdr_loc;
+    } else if (_type == URL) {
+      bufp = res.bufp;
+      hdr_loc = res.hdr_loc;
+    } else {
+      TSError("header_rewrite: Rule not supported at this hook");
+      return false;
+    }
+    if (TSHttpHdrUrlGet(bufp, hdr_loc, &url) != TS_SUCCESS) {
+      TSError("header_rewrite: Error getting the URL");
+      return false;
+    }
+  }
+
+  if (_url_qual == URL_QUAL_HOST) {
+    int host_len = 0;
+    const char *host = TSUrlHostGet(bufp, url, &host_len);
+    s.append(host, host_len);
+    TSDebug(PLUGIN_NAME, "   Host to match is: %.*s", host_len, host);
+  }
+
+  return static_cast<const Matchers<std::string> *>(_matcher)->test(s);
 }
 
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/a67211bf/plugins/header_rewrite/conditions.h
----------------------------------------------------------------------
diff --git a/plugins/header_rewrite/conditions.h b/plugins/header_rewrite/conditions.h
index 7a78775..5b898d8 100644
--- a/plugins/header_rewrite/conditions.h
+++ b/plugins/header_rewrite/conditions.h
@@ -278,7 +278,10 @@ private:
 class ConditionUrl : public Condition
 {
 public:
-  explicit ConditionUrl(bool client = false) : _url_qual(URL_QUAL_NONE), _client(client)
+  enum UrlType { CLIENT, URL, FROM, TO };
+
+
+  explicit ConditionUrl(const UrlType type) : _url_qual(URL_QUAL_NONE), _type(type)
   {
     TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for ConditionUrl");
   };
@@ -294,7 +297,7 @@ private:
   DISALLOW_COPY_AND_ASSIGN(ConditionUrl);
 
   UrlQualifiers _url_qual;
-  bool _client;
+  UrlType _type;
 };
 
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/a67211bf/plugins/header_rewrite/factory.cc
----------------------------------------------------------------------
diff --git a/plugins/header_rewrite/factory.cc b/plugins/header_rewrite/factory.cc
index f279b43..5107a0b 100644
--- a/plugins/header_rewrite/factory.cc
+++ b/plugins/header_rewrite/factory.cc
@@ -103,10 +103,14 @@ condition_factory(const std::string &cond)
     c = new ConditionHeader(true);
   } else if (c_name == "QUERY") {
     c = new ConditionQuery();
-  } else if (c_name == "URL") { // This condition adapts to the hook
-    c = new ConditionUrl();
-  } else if (c_name == "CLIENT-URL") {
-    c = new ConditionUrl(true);
+  } else if (c_name == "CLIENT-URL") { // This condition adapts to the hook
+    c = new ConditionUrl(ConditionUrl::CLIENT);
+  } else if (c_name == "URL") {
+    c = new ConditionUrl(ConditionUrl::URL);
+  } else if (c_name == "FROM-URL") {
+    c = new ConditionUrl(ConditionUrl::FROM);
+  } else if (c_name == "TO-URL") {
+    c = new ConditionUrl(ConditionUrl::TO);
   } else if (c_name == "DBM") {
     c = new ConditionDBM();
   } else if (c_name == "INTERNAL-TRANSACTION") {


[2/2] trafficserver git commit: TS:2609: Updated CHANGES

Posted by bc...@apache.org.
TS:2609: Updated CHANGES


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

Branch: refs/heads/master
Commit: a48c1c431bab2f0edaf5214f1cc18dc2239417be
Parents: a67211b
Author: Bryan Call <bc...@apache.org>
Authored: Mon May 11 15:53:01 2015 -0700
Committer: Bryan Call <bc...@apache.org>
Committed: Mon May 11 15:53:01 2015 -0700

----------------------------------------------------------------------
 CHANGES | 2 ++
 1 file changed, 2 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/a48c1c43/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 073c070..1d107dc 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,8 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache Traffic Server 6.0.0
 
+  *) [TS-2609] Header rewrite plugin *URL:HOST condition
+
   *) [TS-3565] Only start up the continuation from DoRemap if the request has
    a Range: header.