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

Method appendPrefix

plugins/cachekey/cachekey.cc:380–427  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

378 * @note if both prefix and pattern are not empty prefix will be added first, followed by the results from pattern.
379 */
380void
381CacheKey::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,

Callers 1

setCacheKeyFunction · 0.80

Calls 6

getCanonicalUrlFunction · 0.85
getUriFunction · 0.85
appendFunction · 0.70
emptyMethod · 0.45
c_strMethod · 0.45
processMethod · 0.45

Tested by

no test coverage detected