| 254 | } |
| 255 | |
| 256 | void CookieCache::UpdateCachedCookies(const CallHeaders& incoming_headers) { |
| 257 | CookieHeaderPair header_values = incoming_headers.equal_range("set-cookie"); |
| 258 | const std::lock_guard<std::mutex> guard(mutex_); |
| 259 | |
| 260 | for (auto it = header_values.first; it != header_values.second; ++it) { |
| 261 | const std::string_view& value = it->second; |
| 262 | Cookie cookie = Cookie::Parse(value); |
| 263 | |
| 264 | // Cache cookies regardless of whether or not they are expired. The server may have |
| 265 | // explicitly sent a Set-Cookie to expire a cached cookie. |
| 266 | auto insertable = cookies.insert({cookie.GetName(), cookie}); |
| 267 | |
| 268 | // Force overwrite on insert collision. |
| 269 | if (!insertable.second) { |
| 270 | insertable.first->second = cookie; |
| 271 | } |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | std::string CookieCache::GetValidCookiesAsString() { |
| 276 | const std::lock_guard<std::mutex> guard(mutex_); |