You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2018/02/28 17:31:54 UTC
[trafficserver] 01/06: Proper support fort he %{URL:}
conditions
This is an automated email from the ASF dual-hosted git repository.
zwoop pushed a commit to branch 7.1.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit 363405e6cd07419208fb22b8cb36d59051296aae
Author: Leif Hedstrom <zw...@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}
(cherry picked from commit 8fe3dd266d05d21b2e5bec5f6d914e8eac75e2ac)
Conflicts:
doc/admin-guide/plugins/header_rewrite.en.rst
plugins/header_rewrite/conditions.cc
---
doc/admin-guide/plugins/header_rewrite.en.rst | 13 ++++-
plugins/header_rewrite/conditions.cc | 76 +++++++++++++++++++--------
2 files changed, 65 insertions(+), 24 deletions(-)
diff --git a/doc/admin-guide/plugins/header_rewrite.en.rst b/doc/admin-guide/plugins/header_rewrite.en.rst
index 7c10ca5..bfab99d 100644
--- a/doc/admin-guide/plugins/header_rewrite.en.rst
+++ b/doc/admin-guide/plugins/header_rewrite.en.rst
@@ -349,6 +349,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
~~~~~
::
@@ -359,6 +363,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
~~~~~~
::
@@ -417,14 +425,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 4b57dba..d72bfbd 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;
}
}
--
To stop receiving notification emails like this one, please contact
zwoop@apache.org.