* @brief Append to the cache key a custom prefix, capture from hots:port, capture from URI or default to host:port part of the * URI. * @note This is the only cache key component from the key which is always available. * @param prefix if not empty string will append the static prefix to the cache key. * @param prefixCapture if not empty will append regex capture/replacement from the host:port.
| 378 | * @note if both prefix and pattern are not empty prefix will be added first, followed by the results from pattern. |
| 379 | */ |
| 380 | void |
| 381 | CacheKey::appendPrefix(const String &prefix, Pattern &prefixCapture, Pattern &prefixCaptureUri, bool canonicalPrefix) |
| 382 | { |
| 383 | // "true" would mean that the plugin config meant to override the default prefix, "false" means use default. |
| 384 | bool customPrefix = false; |
| 385 | |
| 386 | /* For all the following operations if a canonical prefix is required then append to the key with no separator |
| 387 | * to leave the door open for potential valid host name formed in the final resulting cache key. */ |
| 388 | |
| 389 | if (!prefix.empty()) { |
| 390 | customPrefix = true; |
| 391 | append(prefix, /* useSeparator */ !canonicalPrefix); |
| 392 | CacheKeyDebug("added static prefix, key: '%s'", _key.c_str()); |
| 393 | } |
| 394 | |
| 395 | if (!prefixCapture.empty()) { |
| 396 | customPrefix = true; |
| 397 | |
| 398 | StringVector captures; |
| 399 | if (prefixCapture.process(getCanonicalUrl(_buf, _url, canonicalPrefix, /* provideDefaultKey */ false), captures)) { |
| 400 | for (auto &capture : captures) { |
| 401 | append(capture, /* useSeparator */ !canonicalPrefix); |
| 402 | } |
| 403 | CacheKeyDebug("added host:port capture prefix, key: '%s'", _key.c_str()); |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | if (!prefixCaptureUri.empty()) { |
| 408 | customPrefix = true; |
| 409 | |
| 410 | String uri = getUri(_buf, _url); |
| 411 | if (!uri.empty()) { |
| 412 | StringVector captures; |
| 413 | if (prefixCaptureUri.process(uri, captures)) { |
| 414 | for (auto &capture : captures) { |
| 415 | append(capture, /* useSeparator */ !canonicalPrefix); |
| 416 | } |
| 417 | CacheKeyDebug("added URI capture prefix, key: '%s'", _key.c_str()); |
| 418 | } |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | if (!customPrefix) { |
| 423 | /* nothing was customized => default prefix */ |
| 424 | append(getCanonicalUrl(_buf, _url, canonicalPrefix, /* provideDefaultKey */ true), /* useSeparator */ false); |
| 425 | CacheKeyDebug("added default prefix, key: '%s'", _key.c_str()); |
| 426 | } |
| 427 | } |
| 428 | |
| 429 | /** |
| 430 | * @brief Appends to the cache key the path from the URI (default), regex capture/replacement from the URI path, |
no test coverage detected