trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zw...@apache.org
Subject [trafficserver] branch master updated: Proper support fort he %{URL:<qual>} conditions
Date Mon, 24 Apr 2017 21:51:00 GMT
This is an automated email from the ASF dual-hosted git repository.

zwoop 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  8fe3dd2   Proper support fort he %{URL:<qual>} conditions
8fe3dd2 is described below

commit 8fe3dd266d05d21b2e5bec5f6d914e8eac75e2ac
Author: Leif Hedstrom <zwoop@apache.org>
AuthorDate: Thu Apr 20 12:50:53 2017 -0600

    Proper support fort he %{URL:<qual>} conditions
    
    This was never properly, or completely, implemented. This makes sure that
    the URL conditions works as both conditions and values. Supported qualifiers
    are e.g.
    
    cond %{SEND_RESPONSE_HDR_HOOK} [AND]
    cond %{CLIENT-URL:SCHEME} =http
         set-header X-Url %{CLIENT-URL}
         set-header X-Url-Scheme %{CLIENT-URL:SCHEME}
         set-header X-Url-Host %{CLIENT-URL:HOST}
         set-header X-Url-Port %{CLIENT-URL:PORT}
         set-header X-Url-Path %{CLIENT-URL:PATH}
         set-header X-Url-Query %{CLIENT-URL:QUERY}
         set-header X-Url-Matrix %{CLIENT-URL:MATRIX}
---
 doc/admin-guide/plugins/header_rewrite.en.rst | 15 ++++--
 plugins/header_rewrite/conditions.cc          | 78 +++++++++++++++++++--------
 2 files changed, 67 insertions(+), 26 deletions(-)

diff --git a/doc/admin-guide/plugins/header_rewrite.en.rst b/doc/admin-guide/plugins/header_rewrite.en.rst
index ee08669..b4a77d8 100644
--- a/doc/admin-guide/plugins/header_rewrite.en.rst
+++ b/doc/admin-guide/plugins/header_rewrite.en.rst
@@ -179,7 +179,7 @@ CLIENT-IP
 Remote IP address, as a string, of the client connection for the current
 transaction.
 
-This condition is *deprecated* as of ATS v7.2.x, please use %{IP:CLIENT} instead.
+This condition is *deprecated* as of ATS v7.1.x, please use %{IP:CLIENT} instead.
 
 CLIENT-URL
 ~~~~~~~~~~
@@ -376,6 +376,10 @@ first).
 Refer to `Requests vs. Responses`_ for more information on determining the
 context in which the transaction's URL is evaluated.
 
+This condition is *deprecated* as of ATS v7.1.x, please use e.g. %{URL:PATH}
+or %{CLIENT-URL:PATH} instead.
+
+
 QUERY
 ~~~~~
 ::
@@ -386,6 +390,10 @@ The query parameters, if any, of the transaction.  Refer to `Requests
vs.
 Responses`_ for more information on determining the context in which the
 transaction's URL is evaluated.
 
+This condition is *deprecated* as of ATS v7.1.x, please use e.g. %{URL:QUERY}
+or %{CLIENT-URL:QUERY} instead.
+
+
 RANDOM
 ~~~~~~
 ::
@@ -444,14 +452,15 @@ URL
 ~~~
 ::
 
-    cond %{URL:option} <operand>
+    cond %{URL:<part>} <operand>
 
 The complete URL of the current transaction. This will automatically choose the
 most relevant URL depending upon the hook context in which the condition is
 being evaluated.
 
 Refer to `Requests vs. Responses`_ for more information on determining the
-context in which the transaction's URL is evaluated.
+context in which the transaction's URL is evaluated.  The ``<part>`` may be
+specified according to the options documented in `URL Parts`_.
 
 Condition Operands
 ------------------
diff --git a/plugins/header_rewrite/conditions.cc b/plugins/header_rewrite/conditions.cc
index e18ffa0..6b95892 100644
--- a/plugins/header_rewrite/conditions.cc
+++ b/plugins/header_rewrite/conditions.cc
@@ -62,10 +62,7 @@ ConditionStatus::eval(const Resources &res)
 void
 ConditionStatus::append_value(std::string &s, const Resources &res)
 {
-  std::ostringstream oss;
-
-  oss << res.resp_status;
-  s += oss.str();
+  s += std::to_string(res.resp_status);
   TSDebug(PLUGIN_NAME, "Appending STATUS(%d) to evaluation value -> %s", res.resp_status,
s.c_str());
 }
 
@@ -231,7 +228,7 @@ ConditionHeader::append_value(std::string &s, const Resources &res)
       s.append(value, len);
       // multiple headers with the same name must be semantically the same as one value which
is comma separated
       if (next_field_loc) {
-        s.append(",");
+        s += ',';
       }
       TSHandleMLocRelease(bufp, hdr_loc, field_loc);
       field_loc = next_field_loc;
@@ -348,17 +345,10 @@ ConditionUrl::set_qualifier(const std::string &q)
 }
 
 void
-ConditionUrl::append_value(std::string & /* s ATS_UNUSED */, const Resources & /*
res ATS_UNUSED */)
-{
-}
-
-bool
-ConditionUrl::eval(const Resources &res)
+ConditionUrl::append_value(std::string &s, const Resources &res)
 {
-  TSDebug(PLUGIN_NAME, "ConditionUrl::eval");
   TSMLoc url     = nullptr;
   TSMBuffer bufp = nullptr;
-  std::string s;
 
   if (res._rri != nullptr) {
     // called at the remap hook
@@ -375,7 +365,7 @@ ConditionUrl::eval(const Resources &res)
       url = res._rri->mapToUrl;
     } else {
       TSError("[header_rewrite] Invalid option value");
-      return false;
+      return;
     }
   } else {
     TSMLoc hdr_loc = nullptr;
@@ -387,21 +377,63 @@ ConditionUrl::eval(const Resources &res)
       hdr_loc = res.hdr_loc;
     } else {
       TSError("[header_rewrite] Rule not supported at this hook");
-      return false;
+      return;
     }
     if (TSHttpHdrUrlGet(bufp, hdr_loc, &url) != TS_SUCCESS) {
       TSError("[header_rewrite] Error getting the URL");
-      return false;
+      return;
     }
   }
 
-  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);
+  int i;
+  const char *q_str;
+
+  switch (_url_qual) {
+  case URL_QUAL_HOST:
+    q_str = TSUrlHostGet(bufp, url, &i);
+    s.append(q_str, i);
+    TSDebug(PLUGIN_NAME, "   Host to match is: %.*s", i, q_str);
+    break;
+  case URL_QUAL_PORT:
+    i = TSUrlPortGet(bufp, url);
+    s.append(std::to_string(i));
+    TSDebug(PLUGIN_NAME, "   Port to match is: %d", i);
+    break;
+  case URL_QUAL_PATH:
+    q_str = TSUrlPathGet(bufp, url, &i);
+    s.append(q_str, i);
+    TSDebug(PLUGIN_NAME, "   Path to match is: %.*s", i, q_str);
+    break;
+  case URL_QUAL_QUERY:
+    q_str = TSUrlHttpQueryGet(bufp, url, &i);
+    s.append(q_str, i);
+    TSDebug(PLUGIN_NAME, "   Query parameters to match is: %.*s", i, q_str);
+    break;
+  case URL_QUAL_MATRIX:
+    q_str = TSUrlHttpParamsGet(bufp, url, &i);
+    s.append(q_str, i);
+    TSDebug(PLUGIN_NAME, "   Matrix parameters to match is: %.*s", i, q_str);
+    break;
+  case URL_QUAL_SCHEME:
+    q_str = TSUrlSchemeGet(bufp, url, &i);
+    s.append(q_str, i);
+    TSDebug(PLUGIN_NAME, "   Scheme to match is: %.*s", i, q_str);
+    break;
+  case URL_QUAL_URL:
+  case URL_QUAL_NONE:
+    q_str = TSUrlStringGet(bufp, url, &i);
+    s.append(q_str, i);
+    TSDebug(PLUGIN_NAME, "   URL to match is: %.*s", i, q_str);
+    break;
   }
+}
 
+bool
+ConditionUrl::eval(const Resources &res)
+{
+  std::string s;
+
+  append_value(s, res);
   return static_cast<const Matchers<std::string> *>(_matcher)->test(s);
 }
 
@@ -577,7 +609,7 @@ ConditionClientIp::append_value(std::string &s, const Resources &res)
   char ip[INET6_ADDRSTRLEN];
 
   if (getIP(TSHttpTxnClientAddrGet(res.txnp), ip)) {
-    s.append(ip);
+    s += ip;
   }
 }
 
@@ -647,7 +679,7 @@ ConditionIp::append_value(std::string &s, const Resources &res)
   }
 
   if (ip_set) {
-    s.append(ip);
+    s += ip;
   }
 }
 

-- 
To stop receiving notification emails like this one, please contact
['"commits@trafficserver.apache.org" <commits@trafficserver.apache.org>'].

Mime
View raw message