mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:47:35 +00:00
Browser: Allow changing of existing Cookies in the CookieJar
And attach all the plumbing through to Tab over BrowserWindow.
This commit is contained in:
parent
813ca5ebbe
commit
30360918d4
4 changed files with 35 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Tim Flynn <trflynn89@serenityos.org>
|
||||
* Copyright (c) 2022, the SerenityOS developers.
|
||||
* Copyright (c) 2022, Tobias Christiansen <tobyase@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -48,6 +49,34 @@ void CookieJar::set_cookie(const URL& url, Web::Cookie::ParsedCookie const& pars
|
|||
purge_expired_cookies();
|
||||
}
|
||||
|
||||
// This is based on https://www.rfc-editor.org/rfc/rfc6265#section-5.3 as store_cookie() below
|
||||
// however the whole ParsedCookie->Cookie conversion is skipped.
|
||||
void CookieJar::update_cookie(URL const& url, Web::Cookie::Cookie cookie)
|
||||
{
|
||||
auto domain = canonicalize_domain(url);
|
||||
if (!domain.has_value())
|
||||
return;
|
||||
|
||||
// 6. If the canonicalized request-host does not domain-match the domain-attribute: Ignore the cookie entirely and abort these steps.
|
||||
if (!domain_matches(domain.value(), cookie.domain))
|
||||
return;
|
||||
|
||||
// 11. If the cookie store contains a cookie with the same name, domain, and path as the newly created cookie:
|
||||
CookieStorageKey key { cookie.name, cookie.domain, cookie.path };
|
||||
|
||||
if (auto old_cookie = m_cookies.find(key); old_cookie != m_cookies.end()) {
|
||||
// Update the creation-time of the newly created cookie to match the creation-time of the old-cookie.
|
||||
cookie.creation_time = old_cookie->value.creation_time;
|
||||
// Remove the old-cookie from the cookie store.
|
||||
m_cookies.remove(old_cookie);
|
||||
}
|
||||
|
||||
// 12. Insert the newly created cookie into the cookie store.
|
||||
m_cookies.set(key, move(cookie));
|
||||
|
||||
purge_expired_cookies();
|
||||
}
|
||||
|
||||
void CookieJar::dump_cookies() const
|
||||
{
|
||||
constexpr auto key_color = "\033[34;1m"sv;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue