This is an automated email from the ASF dual-hosted git repository.
gancho 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 d49271b cachekey: capture cache key elements from headers
d49271b is described below
commit d49271b167bca3ea9e7a1b0ac0c65c72512a85dc
Author: Gancho Tenev
AuthorDate: Fri Jul 6 17:25:33 2018 -0700
cachekey: capture cache key elements from headers
--capture-header=:
captures elements from header using
and adds them to the cache key.
---
doc/admin-guide/plugins/cachekey.en.rst | 29 ++--
plugins/cachekey/cachekey.cc| 119 +---
plugins/cachekey/cachekey.h | 4 ++
plugins/cachekey/common.h | 2 +
plugins/cachekey/configs.cc | 52 ++
plugins/cachekey/configs.h | 14 +++-
plugins/cachekey/pattern.cc | 12
plugins/cachekey/pattern.h | 2 +
8 files changed, 187 insertions(+), 47 deletions(-)
diff --git a/doc/admin-guide/plugins/cachekey.en.rst
b/doc/admin-guide/plugins/cachekey.en.rst
index 958cdbe..0b631d5 100644
--- a/doc/admin-guide/plugins/cachekey.en.rst
+++ b/doc/admin-guide/plugins/cachekey.en.rst
@@ -110,14 +110,16 @@ Cache key structure and related plugin parameters
::
- Optional components | ┌───┐
- | │ --include-headers │
- | ├───┤
- Default values if no | │ (empty) |
- optional components | └───┘
+ Optional components | ┌───┬┐
+ | │ --include-headers │ --capture-headers │
+ | ├┤
+ Default values if no | │ (empty) | (empty) |
+ optional components | └───┴┘
configured |
-* ``--include-headers`` (default: empty list) - comma separated list of
headers to be added to the cache key. The list of headers defined by
``--include-headers`` are always sorted before adding them to the cache key.
+* ``--include-headers`` (default: empty list) - comma separated list of
headers to be added to the cache key. The list of headers defined by
``--include-headers`` are always sorted before adding them to the cache key.
+
+* ``--capture-header=:`` (default: empty) -
captures elements from header using and adds
them to the cache key.
"Cookies" section
^
@@ -400,6 +402,21 @@ The following headers ``HeaderA`` and ``HeaderB`` will be
used when constructing
@plugin=cachekey.so @pparam=--include-headers=HeaderA,HeaderB
+The following would capture from the ``Authorization`` header and will add the
captured element to the cache key ::
+
+ @plugin=cachekey.so \
+
@pparam=--capture-header=Authorization:/AWS\s(?[^:]+).*/clientID:$1/"
+
+If the request looks like the following::
+
+ http://example-cdn.com/path/file
+ Authorization: AWS MKIARYMOG51PT0DLD:DLiWQ2lyS49H4Zyx34kW0URtg6s=
+
+Cache key would be set to::
+
+ /example-cdn.com/80/clientID:MKIARYMOG51PTCKQ0DLD/path/file
+
+
HTTP Cookies
diff --git a/plugins/cachekey/cachekey.cc b/plugins/cachekey/cachekey.cc
index a31d628..c89b657 100644
--- a/plugins/cachekey/cachekey.cc
+++ b/plugins/cachekey/cachekey.cc
@@ -437,6 +437,61 @@ CacheKey::appendPath(Pattern &pathCapture, Pattern
&pathCaptureUri)
}
}
+template
+void
+CacheKey::processHeader(const String &name, const ConfigHeaders &config, T
&dst,
+void (*fun)(const ConfigHeaders &config, const String
&name_s, const String &value_s, T &captures))
+{
+ TSMLoc field;
+
+ for (field = TSMimeHdrFieldFind(_buf, _hdrs, name.c_str(), name.size());
field != TS_NULL_MLOC;
+ field = ::nextDuplicate(_buf, _hdrs, field)) {
+const char *value;
+int vlen;
+int count = TSMimeHdrFieldValuesCount(_buf, _hdrs, field);
+
+for (int i = 0; i < count; ++i) {
+ value = TSMimeHdrFieldValueStringGet(_buf, _hdrs, field, i, &vlen);
+ if (value == nullptr || vlen == 0) {
+CacheKeyDebug("missing value %d for header %s", i, name.c_str());
+continue;
+ }
+
+ String value_s(value, vlen);
+ fun(config, name, value_s, dst);
+}
+ }
+}
+
+template
+void
+captureWholeHeaders(const ConfigHeaders &config, const String &name, const
String &value, T &captures)
+{
+ CacheKeyDebug("processing header %s", name.c_str());
+ if (config.toBeAdded(name)) {
+String header;
+header.append(name).append(":").append(value);
+captures.insert(header);
+CacheKeyDebug("adding header '%s: %s'", name.c_str(), value.c_str());
+ } else {
+CacheKeyDebug("failed to find header '%s'", name.c_str());
+ }
+}
+
+template
+void
+capture