/* * Copyright (c) 2021, Tim Flynn * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include namespace Browser { struct CookieStorageKey { bool operator==(CookieStorageKey const&) const = default; DeprecatedString name; DeprecatedString domain; DeprecatedString path; }; class CookieJar { public: DeprecatedString get_cookie(const URL& url, Web::Cookie::Source source); void set_cookie(const URL& url, Web::Cookie::ParsedCookie const& parsed_cookie, Web::Cookie::Source source); void update_cookie(URL const&, Web::Cookie::Cookie); void dump_cookies() const; Vector get_all_cookies() const; Vector get_all_cookies(URL const& url); Optional get_named_cookie(URL const& url, DeprecatedString const& name); private: static Optional canonicalize_domain(const URL& url); static bool domain_matches(DeprecatedString const& string, DeprecatedString const& domain_string); static bool path_matches(DeprecatedString const& request_path, DeprecatedString const& cookie_path); static DeprecatedString default_path(const URL& url); enum class MatchingCookiesSpecMode { RFC6265, WebDriver, }; void store_cookie(Web::Cookie::ParsedCookie const& parsed_cookie, const URL& url, DeprecatedString canonicalized_domain, Web::Cookie::Source source); Vector get_matching_cookies(const URL& url, DeprecatedString const& canonicalized_domain, Web::Cookie::Source source, MatchingCookiesSpecMode mode = MatchingCookiesSpecMode::RFC6265); void purge_expired_cookies(); HashMap m_cookies; }; } namespace AK { template<> struct Traits : public GenericTraits { static unsigned hash(Browser::CookieStorageKey const& key) { unsigned hash = 0; hash = pair_int_hash(hash, string_hash(key.name.characters(), key.name.length())); hash = pair_int_hash(hash, string_hash(key.domain.characters(), key.domain.length())); hash = pair_int_hash(hash, string_hash(key.path.characters(), key.path.length())); return hash; } }; }