* @brief Constructor setting up the cache key prefix, initializing request info. * @param txn transaction handle. * @param separator cache key elements separator * @param uriType type of the URI used to create the cachekey ("remap" or "pristine") * @param rri remap request info */
| 241 | * @param rri remap request info |
| 242 | */ |
| 243 | CacheKey::CacheKey(TSHttpTxn txn, String separator, CacheKeyUriType uriType, CacheKeyKeyType keyType, TSRemapRequestInfo *rri) |
| 244 | : _txn(txn), _separator(std::move(separator)), _uriType(uriType), _keyType(keyType) |
| 245 | { |
| 246 | _key.reserve(512); |
| 247 | |
| 248 | _remap = (nullptr != rri); |
| 249 | |
| 250 | /* Get the URI and header to base the cachekey on. |
| 251 | * @TODO it might make sense to add more supported URI types */ |
| 252 | |
| 253 | CacheKeyDebug("setting %s from a %s plugin", getCacheKeyKeyTypeName(_keyType), _remap ? "remap" : "global"); |
| 254 | |
| 255 | if (_remap) { |
| 256 | if (PRISTINE == _uriType) { |
| 257 | if (TS_SUCCESS != TSHttpTxnPristineUrlGet(_txn, &_buf, &_url)) { |
| 258 | /* Failing here is unlikely. No action seems the only reasonable thing to do from within this plug-in */ |
| 259 | CacheKeyError("failed to get pristine URI handle"); |
| 260 | return; |
| 261 | } |
| 262 | CacheKeyDebug("using pristine uri '%s'", getUri(_buf, _url).c_str()); |
| 263 | } else { |
| 264 | _buf = rri->requestBufp; |
| 265 | _url = rri->requestUrl; |
| 266 | CacheKeyDebug("using remap uri '%s'", getUri(_buf, _url).c_str()); |
| 267 | } |
| 268 | _hdrs = rri->requestHdrp; |
| 269 | } else { |
| 270 | if (TS_SUCCESS != TSHttpTxnClientReqGet(_txn, &_buf, &_hdrs)) { |
| 271 | /* Failing here is unlikely. No action seems the only reasonable thing to do from within this plug-in */ |
| 272 | CacheKeyError("failed to get client request handle"); |
| 273 | return; |
| 274 | } |
| 275 | |
| 276 | if (PRISTINE == _uriType) { |
| 277 | if (TS_SUCCESS != TSHttpTxnPristineUrlGet(_txn, &_buf, &_url)) { |
| 278 | TSHandleMLocRelease(_buf, TS_NULL_MLOC, _hdrs); |
| 279 | CacheKeyError("failed to get pristine URI handle"); |
| 280 | return; |
| 281 | } |
| 282 | CacheKeyDebug("using pristine uri '%s'", getUri(_buf, _url).c_str()); |
| 283 | } else { |
| 284 | if (TS_SUCCESS != TSHttpHdrUrlGet(_buf, _hdrs, &_url)) { |
| 285 | TSHandleMLocRelease(_buf, TS_NULL_MLOC, _hdrs); |
| 286 | CacheKeyError("failed to get URI handle"); |
| 287 | return; |
| 288 | } |
| 289 | CacheKeyDebug("using post-remap uri '%s','", getUri(_buf, _url).c_str()); |
| 290 | } |
| 291 | } |
| 292 | _valid = true; /* success, we got all necessary elements - URI, headers, etc. */ |
| 293 | } |
| 294 | |
| 295 | CacheKey::~CacheKey() |
| 296 | { |
nothing calls this directly
no test coverage detected