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

Function getDescriptionFromUrl

plugins/experimental/rate_limit/utilities.cc:85–124  ·  view source on GitHub ↗

////////////////////////////////////////////////////////////////////////// Parse a URL to obtain a description for use with metrics when no user provided tag is available. This is used by the remap side of the plugin, while the SNI side uses the FQDN associated with each limiter instance which is obtained from the list of SNIs in the global plugin configuration.

Source from the content-addressed store, hash-verified

83// which is obtained from the list of SNIs in the global plugin configuration.
84//
85std::string
86getDescriptionFromUrl(const char *url)
87{
88 TSMBuffer const buf = TSMBufferCreate();
89 TSMLoc url_loc = nullptr;
90
91 const int url_len = strlen(url);
92 std::string description;
93
94 if (TS_SUCCESS == TSUrlCreate(buf, &url_loc) && TS_PARSE_DONE == TSUrlParse(buf, url_loc, &url, url + url_len)) {
95 int host_len, scheme_len = 0;
96 const char *s = TSUrlSchemeGet(buf, url_loc, &scheme_len);
97 const char *h = TSUrlHostGet(buf, url_loc, &host_len);
98 const int port = TSUrlPortGet(buf, url_loc);
99
100 const std::string hostname = std::string(h, host_len);
101 const std::string scheme = std::string(s, scheme_len);
102
103 Dbg(dbg_ctl, "scheme = %s, host = %s, port = %d", scheme.c_str(), hostname.c_str(), port);
104
105 description = scheme;
106 description.append(".");
107 description.append(hostname);
108
109 // only append the port when it is non-standard
110 if (!(strncmp(s, TS_URL_SCHEME_HTTP, scheme_len) == 0 && port == 80) &&
111 !(strncmp(s, TS_URL_SCHEME_HTTPS, scheme_len) == 0 && port == 443)) {
112 description.push_back(':');
113 description.append(std::to_string(port));
114 }
115 }
116
117 if (url_loc != nullptr) {
118 TSHandleMLocRelease(buf, nullptr, url_loc);
119 }
120
121 TSMBufferDestroy(buf);
122
123 return description;
124}

Callers 1

TSRemapNewInstanceFunction · 0.85

Calls 13

TSMBufferCreateFunction · 0.85
TSUrlCreateFunction · 0.85
TSUrlParseFunction · 0.85
TSUrlSchemeGetFunction · 0.85
TSUrlHostGetFunction · 0.85
TSUrlPortGetFunction · 0.85
stringClass · 0.85
TSHandleMLocReleaseFunction · 0.85
TSMBufferDestroyFunction · 0.85
to_stringClass · 0.50
c_strMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected