* @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. */
| 229 | * @note Add the cookies to "hier-part" (RFC 3986), always sort them in the cache key. |
| 230 | */ |
| 231 | bool |
| 232 | getCookieByName(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. |
no test coverage detected