Repository navigation
Replies: 1 comment
|
For a test cookie with an expiry, use the public underlying CookieJar and the standard-library Cookie object. Cookies.set does not accept max_age on HTTPX 0.28.1: from http.cookiejar import Cookie
from time import time
def set_expiring_cookie(client, name, value, *, domain, path="/", max_age=86400):
cookie = Cookie(
version=0, name=name, value=str(value),
port=None, port_specified=False,
domain=domain, domain_specified=False, domain_initial_dot=False,
path=path, path_specified=True, secure=False,
expires=int(time()) + max_age, discard=False,
comment=None, comment_url=None, rest={}, rfc2109=False,
)
client.cookies.jar.set_cookie(cookie)Use a dotted request host such as
Validated future and expired cookies through MockTransport using a dotted test host, including expiry cleanup. stdlib CookieJar, HTTPX cookies. Validation version: HTTPX 0.28.1, Python 3.11.9. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Feature Request
The current signature of Cookies.set could be updated to allow passing in
expires. Or evenmax_agewhich is a bit more user-friendly.Use Case
I have this test utility function:
In the meantime, here's a workaround.
All reactions