Skip to content

Commit b886123

Browse files
authored
Add matrix params to the cachekey in the cachekey plugin (#11856)
1 parent 5e39658 commit b886123

File tree

5 files changed

+51
-0
lines changed

5 files changed

+51
-0
lines changed

plugins/cachekey/cachekey.cc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,27 @@ CacheKey::appendQuery(const ConfigQuery &config)
673673
}
674674
}
675675

676+
void
677+
CacheKey::appendMatrix(const ConfigMatrix &config)
678+
{
679+
if (config.toBeRemoved()) {
680+
return;
681+
}
682+
683+
const char *matrix;
684+
int length;
685+
686+
matrix = TSUrlHttpParamsGet(_buf, _url, &length);
687+
if (matrix == nullptr || length == 0) {
688+
return;
689+
}
690+
691+
if (matrix && length) {
692+
_key.append(";");
693+
_key.append(matrix, length);
694+
}
695+
}
696+
676697
/**
677698
* @brief Append User-Agent header captures specified in the Pattern configuration object.
678699
*

plugins/cachekey/cachekey.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class CacheKey
6363
void appendPath(Pattern &pathCapture, Pattern &pathCaptureUri);
6464
void appendHeaders(const ConfigHeaders &config);
6565
void appendQuery(const ConfigQuery &config);
66+
void appendMatrix(const ConfigMatrix &config);
6667
void appendCookies(const ConfigCookies &config);
6768
void appendUaCaptures(Pattern &config);
6869
bool appendUaClass(Classifier &classifier);

plugins/cachekey/configs.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,20 @@ ConfigQuery::name() const
208208
return _NAME;
209209
}
210210

211+
bool
212+
ConfigMatrix::finalize()
213+
{
214+
_remove = noIncludeExcludeRules();
215+
return true;
216+
}
217+
218+
const String ConfigMatrix::_NAME = "matrix parameter";
219+
inline const String &
220+
ConfigMatrix::name() const
221+
{
222+
return _NAME;
223+
}
224+
211225
/**
212226
* @briefs finalizes the headers related configuration.
213227
*

plugins/cachekey/configs.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,16 @@ class ConfigQuery : public ConfigElements
112112
static const String _NAME;
113113
};
114114

115+
class ConfigMatrix : public ConfigElements
116+
{
117+
public:
118+
bool finalize() override;
119+
120+
private:
121+
const String &name() const override;
122+
static const String _NAME;
123+
};
124+
115125
/**
116126
* @brief Headers configuration class.
117127
*/
@@ -210,6 +220,7 @@ class Configs
210220
/* Make the following members public to avoid unnecessary accessors */
211221
ConfigQuery _query; /**< @brief query parameter related configuration */
212222
ConfigHeaders _headers; /**< @brief headers related configuration */
223+
ConfigMatrix _matrix; /**< @brief matrix parameter related configuration */
213224
ConfigCookies _cookies; /**< @brief cookies related configuration */
214225
Pattern _uaCapture; /**< @brief the capture groups and the replacement string used for the User-Agent header capture */
215226
String _prefix; /**< @brief cache key prefix string */

plugins/cachekey/plugin.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ setCacheKey(TSHttpTxn txn, Configs *config, TSRemapRequestInfo *rri = nullptr)
6464
if (!config->pathToBeRemoved()) {
6565
cachekey.appendPath(config->_pathCapture, config->_pathCaptureUri);
6666
}
67+
68+
/* Append the matrix parameters to the cache key. */
69+
cachekey.appendMatrix(config->_matrix);
70+
6771
/* Append query parameters to the cache key. */
6872
cachekey.appendQuery(config->_query);
6973

0 commit comments

Comments
 (0)