| 189 | } |
| 190 | |
| 191 | static String |
| 192 | getCanonicalUrl(TSMBuffer buf, TSMLoc url, bool canonicalPrefix, bool provideDefaultKey) |
| 193 | { |
| 194 | String canonicalUrl; |
| 195 | |
| 196 | String scheme; |
| 197 | int schemeLen; |
| 198 | const char *schemePtr = TSUrlSchemeGet(buf, url, &schemeLen); |
| 199 | if (nullptr != schemePtr && 0 != schemeLen) { |
| 200 | scheme.assign(schemePtr, schemeLen); |
| 201 | } else { |
| 202 | CacheKeyError("failed to get scheme"); |
| 203 | return canonicalUrl; |
| 204 | } |
| 205 | |
| 206 | String host; |
| 207 | int hostLen; |
| 208 | const char *hostPtr = TSUrlHostGet(buf, url, &hostLen); |
| 209 | if (nullptr != hostPtr && 0 != hostLen) { |
| 210 | host.assign(hostPtr, hostLen); |
| 211 | } else { |
| 212 | CacheKeyError("failed to get host"); |
| 213 | return canonicalUrl; |
| 214 | } |
| 215 | |
| 216 | String port; |
| 217 | int portInt = TSUrlPortGet(buf, url); |
| 218 | ::append(port, portInt); |
| 219 | |
| 220 | if (canonicalPrefix) { |
| 221 | /* return the same for both regex input or default key, results in 'scheme://host:port' */ |
| 222 | canonicalUrl.assign(scheme).append("://").append(host).append(":").append(port); |
| 223 | } else { |
| 224 | if (provideDefaultKey) { |
| 225 | /* return the key default - results in '/host/port' */ |
| 226 | canonicalUrl.assign(1, '/').append(host).append("/").append(port); |
| 227 | } else { |
| 228 | /* return regex input string - results in 'host:port' (use-case kept for compatibility reasons) */ |
| 229 | canonicalUrl.assign(host).append(":").append(port); |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | return canonicalUrl; |
| 234 | } |
| 235 | |
| 236 | /** |
| 237 | * @brief Constructor setting up the cache key prefix, initializing request info. |
no test coverage detected