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

Function getCookieByName

plugins/experimental/access_control/plugin.cc:231–268  ·  view source on GitHub ↗

* @brief Append cookies by following the rules specified in the cookies config object. * @param config cookies-related configuration containing information about which cookies need to be appended to the key. * @note Add the cookies to "hier-part" (RFC 3986), always sort them in the cache key. */

Source from the content-addressed store, hash-verified

229 * @note Add the cookies to "hier-part" (RFC 3986), always sort them in the cache key.
230 */
231bool
232getCookieByName(TSHttpTxn /* txn ATS_UNUSED */, TSMBuffer buf, TSMLoc hdrs, const String &cookieName, String &cookieValue)
233{
234 TSMLoc field;
235
236 for (field = TSMimeHdrFieldFind(buf, hdrs, TS_MIME_FIELD_COOKIE, TS_MIME_LEN_COOKIE); field != TS_NULL_MLOC;
237 field = ::nextDuplicate(buf, hdrs, field)) {
238 int count = TSMimeHdrFieldValuesCount(buf, hdrs, field);
239
240 for (int i = 0; i < count; ++i) {
241 const char *val;
242 int len;
243
244 val = TSMimeHdrFieldValueStringGet(buf, hdrs, field, i, &len);
245 if (val == nullptr || len == 0) {
246 continue;
247 }
248
249 String cookie;
250 std::istringstream istr(String(val, len));
251
252 while (std::getline(istr, cookie, ';')) {
253 ::ltrim(cookie); // Trim leading spaces.
254
255 String::size_type pos(cookie.find_first_of('='));
256 String name(cookie.substr(0, pos == String::npos ? cookie.size() : pos));
257
258 AccessControlDebug("cookie name: %s", name.c_str());
259
260 if (0 == cookieName.compare(name)) {
261 cookieValue.assign(cookie.substr(pos == String::npos ? pos : pos + 1));
262 return true;
263 }
264 }
265 }
266 }
267 return false;
268}
269
270/**
271 * @brief Handle token validation failures.

Callers 1

enforceAccessControlFunction · 0.85

Calls 11

TSMimeHdrFieldFindFunction · 0.85
nextDuplicateFunction · 0.70
ltrimFunction · 0.70
StringClass · 0.50
substrMethod · 0.45
sizeMethod · 0.45
c_strMethod · 0.45
compareMethod · 0.45
assignMethod · 0.45

Tested by

no test coverage detected