Skip to content

Cookie Management ## Business Purpose

Manage HTTP cookies across requests, including automatic cookie extraction from responses and flexible cookie jar with case-insensitive access and domain/path filtering. ## Current Behaviors - MockRequest wraps a PreparedRequest for compatibility with standard http.cookiejar src/requests/cookies.py:31. - extract_cookies_to_jar() extracts cookies from a response into a CookieJar src/requests/cookies.py:135. - remove_cookie_by_name() removes cookies by name, optionally filtered by domain/path src/requests/cookies.py:164. - RequestsCookieJar extends CookieJar and MutableMapping, providing dict-like access with case-insensitive keys and get_dict(), list_domains(), list_paths() methods src/requests/cookies.py:191. - create_cookie() creates a Cookie from name, value, and optional attributes src/requests/cookies.py:494. - merge_cookies() merges cookies from a dict or another jar, raising ValueError for invalid jar src/requests/cookies.py:604. ## Technical Implementation Cookies are stored in the Session's cookies attribute (a RequestsCookieJar). The Session's send method extracts cookies from each response and merges them into the jar src/requests/sessions.py:752. ## Definition of Done - Cookies set by a server are automatically included in subsequent requests to the same domain. - session.cookies.get('name') returns the cookie value or raises CookieConflictError for duplicate names without domain. - session.cookies.list_domains() returns unique domains. - Merging a dict of cookies with merge_cookies does not overwrite existing cookies. - RequestsCookieJar can be pickled and unpickled.