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

Function getCanonicalUrl

plugins/cachekey/cachekey.cc:191–234  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

189}
190
191static String
192getCanonicalUrl(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.

Callers 1

appendPrefixMethod · 0.85

Calls 6

TSUrlSchemeGetFunction · 0.85
TSUrlHostGetFunction · 0.85
TSUrlPortGetFunction · 0.85
appendFunction · 0.70
assignMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected