* @brief Update cache key. * @return true if success, false if failed to set the cache key. */
| 743 | * @return true if success, false if failed to set the cache key. |
| 744 | */ |
| 745 | bool |
| 746 | CacheKey::finalize() const |
| 747 | { |
| 748 | bool res = false; |
| 749 | String msg; |
| 750 | |
| 751 | CacheKeyDebug("finalizing %s '%s' from a %s plugin", getCacheKeyKeyTypeName(_keyType), _key.c_str(), |
| 752 | (_remap ? "remap" : "global")); |
| 753 | switch (_keyType) { |
| 754 | case CACHE_KEY: { |
| 755 | if (TS_SUCCESS == TSCacheUrlSet(_txn, &(_key[0]), _key.size())) { |
| 756 | /* Set cache key successfully */ |
| 757 | msg.assign("set cache key to ").append(_key); |
| 758 | res = true; |
| 759 | } else { |
| 760 | if (_remap) { |
| 761 | /* Remap instance. Always runs first by design (before TS_HTTP_POST_REMAP_HOOK) */ |
| 762 | msg.assign("failed to set cache key"); |
| 763 | } else { |
| 764 | /* Global instance. We would fail and get here if a per-remap instance has already set the cache key |
| 765 | * (currently TSCacheUrlSet() can be called only once successfully). Don't error, just debug. |
| 766 | * @todo avoid the consecutive attempts and error only on unexpected failures. */ |
| 767 | msg.assign("failed to set cache key"); |
| 768 | } |
| 769 | } |
| 770 | } break; |
| 771 | case PARENT_SELECTION_URL: { |
| 772 | /* parent selection */ |
| 773 | const char *start = _key.c_str(); |
| 774 | const char *end = _key.c_str() + _key.length(); |
| 775 | TSMLoc new_url_loc; |
| 776 | if (TS_SUCCESS == TSUrlCreate(_buf, &new_url_loc)) { |
| 777 | if (TS_PARSE_DONE == TSUrlParse(_buf, new_url_loc, &start, end)) { |
| 778 | if (TS_SUCCESS == TSHttpTxnParentSelectionUrlSet(_txn, _buf, new_url_loc)) { |
| 779 | msg.assign("set parent selection URL to ").append(_key); |
| 780 | res = true; |
| 781 | } else { |
| 782 | msg.assign("failed to set parent selection URL"); |
| 783 | } |
| 784 | } else { |
| 785 | msg.assign("failed to parse parent selection URL"); |
| 786 | } |
| 787 | TSHandleMLocRelease(_buf, TS_NULL_MLOC, new_url_loc); |
| 788 | } else { |
| 789 | msg.assign("failed to create parent selection URL"); |
| 790 | } |
| 791 | } break; |
| 792 | default: { |
| 793 | msg.assign("unknown target URI type"); |
| 794 | } break; |
| 795 | } |
| 796 | |
| 797 | /* Report status - debug level in case of success, error in case of failure. |
| 798 | * Since getting effective URI is expensive add it only in case of failure */ |
| 799 | if (res) { |
| 800 | CacheKeyDebug("%.*s", static_cast<int>(msg.length()), msg.c_str()); |
| 801 | } else { |
| 802 | int len; |
nothing calls this directly
no test coverage detected