diff --git a/doc/admin-guide/plugins/cachekey.en.rst b/doc/admin-guide/plugins/cachekey.en.rst index 5342d8b52b8..51f4ef174a8 100644 --- a/doc/admin-guide/plugins/cachekey.en.rst +++ b/doc/admin-guide/plugins/cachekey.en.rst @@ -70,20 +70,29 @@ Cache key structure and related plugin parameters :: - Optional components | ┌─────────────────┬──────────────────┬──────────────────────┐ + Optional components | ┌─────────────────┬────────────── ───┬──────────────────────┐ (included in this order) | │ --static-prefix | --capture-prefix │ --capture-prefix-uri │ | ├─────────────────┴──────────────────┴──────────────────────┤ - Default values if no | │ /host/port | + Default values if no | │ /host/port or scheme://host:port (see the table below) | optional components | └───────────────────────────────────────────────────────────┘ configured | + ┌────────────────────┬─────────────────────────┬──────────────────────┐ + │ --canonical-prefix | default value if no │ input used for │ + │ | prefix parameters used │ --capture-prefix │ + ├────────────────────┴─────────────────────────┴──────────────────────┤ + │ fasle | /host/port | host:port | + ├────────────────────┴─────────────────────────┴──────────────────────┤ + │ true | scheme://host:port | scheme://host:port | + └──────────────────────────────────────────────┴──────────────────────┘ + + * ``--static-prefix=`` (default: empty string) - if specified and not an empty string the ```` will be added to the cache key. -* ``--capture-prefix=`` (default: empty string) - if specified and not empty then strings are captured from ``host:port`` based on the ```` and are added to the cache key. +* ``--capture-prefix=`` (default: empty string) - if specified and not empty then strings are captured based on the value of ``--canonical-prefix`` parameter (see the table above) and ```` and are added to the cache key. * ``--capture-prefix-uri=`` (default: empty string) - if specified and not empty then strings are captured from the entire URI based on the ```` and are added to the cache key. * If any of the "Prefix" related plugin parameters are used together in the plugin configuration they are added to the cache key in the order shown in the diagram. -* ``--remove-prefix= default prefix */ + append(getCanonicalUrl(_buf, _url, canonicalPrefix, /* provideDefaultKey */ true), /* useSeparator */ false); CacheKeyDebug("added default prefix, key: '%s'", _key.c_str()); } } diff --git a/plugins/cachekey/cachekey.h b/plugins/cachekey/cachekey.h index 7ea058cb6cf..0922ed104ab 100644 --- a/plugins/cachekey/cachekey.h +++ b/plugins/cachekey/cachekey.h @@ -55,9 +55,10 @@ class CacheKey void append(unsigned number); void append(const String &); + void append(const String &s, bool useSeparator); void append(const char *s); void append(const char *n, unsigned s); - void appendPrefix(const String &prefix, Pattern &prefixCapture, Pattern &prefixCaptureUri); + void appendPrefix(const String &prefix, Pattern &prefixCapture, Pattern &prefixCaptureUri, bool canonicalPrefix); void appendPath(Pattern &pathCapture, Pattern &pathCaptureUri); void appendHeaders(const ConfigHeaders &config); void appendQuery(const ConfigQuery &config); diff --git a/plugins/cachekey/configs.cc b/plugins/cachekey/configs.cc index 2320db14336..a56565c7d93 100644 --- a/plugins/cachekey/configs.cc +++ b/plugins/cachekey/configs.cc @@ -397,6 +397,8 @@ Configs::init(int argc, const char *argv[], bool perRemapConfig) {const_cast("separator"), optional_argument, nullptr, 's'}, {const_cast("uri-type"), optional_argument, nullptr, 't'}, {const_cast("capture-header"), optional_argument, nullptr, 'u'}, + {const_cast("canonical-prefix"), optional_argument, nullptr, 'v'}, + /* reserve 'z' for 'config' files */ {nullptr, 0, nullptr, 0}, }; @@ -504,6 +506,9 @@ Configs::init(int argc, const char *argv[], bool perRemapConfig) case 'u': /* capture-header */ _headers.addCapture(optarg); break; + case 'v': /* canonical-prefix */ + _canonicalPrefix = isTrue(optarg); + break; } } @@ -535,6 +540,12 @@ Configs::pathToBeRemoved() return _pathToBeRemoved; } +bool +Configs::canonicalPrefix() +{ + return _canonicalPrefix; +} + void Configs::setSeparator(const char *arg) { diff --git a/plugins/cachekey/configs.h b/plugins/cachekey/configs.h index 947b21931ea..5ff41f03ccc 100644 --- a/plugins/cachekey/configs.h +++ b/plugins/cachekey/configs.h @@ -162,6 +162,11 @@ class Configs */ bool pathToBeRemoved(); + /** + * @brief keep URI scheme and authority elements. + */ + bool canonicalPrefix(); + /** * @brief set the cache key elements separator string. */ @@ -205,6 +210,7 @@ class Configs bool _prefixToBeRemoved = false; /**< @brief instructs the prefix (i.e. host:port) not to added to the cache key */ bool _pathToBeRemoved = false; /**< @brief instructs the path not to added to the cache key */ + bool _canonicalPrefix = false; /**< @brief keep the URI scheme and authority element used as input to transforming into key */ String _separator = "/"; /**< @brief a separator used to separate the cache key elements extracted from the URI */ CacheKeyUriType _uriType = REMAP; /**< @brief shows which URI the cache key will be based on */ }; diff --git a/plugins/cachekey/plugin.cc b/plugins/cachekey/plugin.cc index 43bad79e3c0..afb9503b0ce 100644 --- a/plugins/cachekey/plugin.cc +++ b/plugins/cachekey/plugin.cc @@ -43,7 +43,7 @@ setCacheKey(TSHttpTxn txn, Configs *config, TSRemapRequestInfo *rri = nullptr) /* Append custom prefix or the host:port */ if (!config->prefixToBeRemoved()) { - cachekey.appendPrefix(config->_prefix, config->_prefixCapture, config->_prefixCaptureUri); + cachekey.appendPrefix(config->_prefix, config->_prefixCapture, config->_prefixCaptureUri, config->canonicalPrefix()); } /* Classify User-Agent and append the class name to the cache key if matched. */ cachekey.appendUaClass(config->_classifier);