* @brief Appends to the cache key the path from the URI (default), regex capture/replacement from the URI path, * regex capture/replacement from URI as whole. * @note A path is always defined for a URI, though the defined path may be empty (zero length) (RFC 3986) * @param pathCapture if not empty will append regex capture/replacement from the URI path * @param pathCaptureUri if not empty will
| 435 | * @todo enhance, i.e. /<regex>/<replace>/ |
| 436 | */ |
| 437 | void |
| 438 | CacheKey::appendPath(Pattern &pathCapture, Pattern &pathCaptureUri) |
| 439 | { |
| 440 | // "true" would mean that the plugin config meant to override the default path. |
| 441 | bool customPath = false; |
| 442 | String path; |
| 443 | |
| 444 | int pathLen; |
| 445 | const char *pathPtr = TSUrlPathGet(_buf, _url, &pathLen); |
| 446 | if (nullptr != pathPtr && 0 != pathLen) { |
| 447 | path.assign(pathPtr, pathLen); |
| 448 | } |
| 449 | |
| 450 | if (!pathCaptureUri.empty()) { |
| 451 | customPath = true; |
| 452 | |
| 453 | String uri = getUri(_buf, _url); |
| 454 | if (!uri.empty()) { |
| 455 | StringVector captures; |
| 456 | if (pathCaptureUri.process(uri, captures)) { |
| 457 | for (auto &capture : captures) { |
| 458 | append(capture); |
| 459 | } |
| 460 | CacheKeyDebug("added URI capture (path), key: '%s'", _key.c_str()); |
| 461 | } |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | if (!pathCapture.empty()) { |
| 466 | customPath = true; |
| 467 | |
| 468 | // If path is empty don't even try to capture/replace. |
| 469 | if (!path.empty()) { |
| 470 | StringVector captures; |
| 471 | if (pathCapture.process(path, captures)) { |
| 472 | for (auto &capture : captures) { |
| 473 | append(capture); |
| 474 | } |
| 475 | CacheKeyDebug("added path capture, key: '%s'", _key.c_str()); |
| 476 | } |
| 477 | } |
| 478 | } |
| 479 | |
| 480 | if (!customPath && !path.empty()) { |
| 481 | append(path); |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | template <class T> |
| 486 | void |
no test coverage detected