MCPcopy Create free account
hub / github.com/apache/trafficserver / appendPath

Method appendPath

plugins/cachekey/cachekey.cc:437–483  ·  view source on GitHub ↗

* @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

Source from the content-addressed store, hash-verified

435 * @todo enhance, i.e. /<regex>/<replace>/
436 */
437void
438CacheKey::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
485template <class T>
486void

Callers 1

setCacheKeyFunction · 0.80

Calls 7

TSUrlPathGetFunction · 0.85
getUriFunction · 0.85
appendFunction · 0.70
assignMethod · 0.45
emptyMethod · 0.45
processMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected