-
-
Notifications
You must be signed in to change notification settings - Fork 858
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option to disable cookie persistence in Client/AsyncClient #2992
Comments
Hi! Example: import httpx
class DisableCookieTransport(httpx.BaseTransport):
def __init__(self, transport: httpx.BaseTransport):
self.transport = transport
def handle_request(self, request: httpx.Request) -> httpx.Response:
response = self.transport.handle_request(request)
del response.headers["set-cookie"]
return response
client = httpx.Client(transport=DisableCookieTransport(httpx.HTTPTransport()))
response = client.get("https://httpbin.org/cookies/set?foo=bar") |
For class AsyncDisableCookieTransport(httpx.AsyncBaseTransport):
def __init__(self, transport: httpx.AsyncBaseTransport):
self.transport = transport
async def handle_async_request(self, request: httpx.Request) -> httpx.Response:
response = await self.transport.handle_async_request(request)
response.headers.pop("set-cookie", None)
return response
client = httpx.AsyncClient(transport=AsyncDisableCookieTransport(httpx.AsyncHTTPTransport())) |
Perhaps this is a common enough use-case that we should add |
I would love to see something like #3065 merged. I consider merging cookies by default to be a possible attack vector, so I would love to turn this off, when not needed. |
+1 for #3065 |
Initially raised as discussion #1533
I've been using
httpx
'sAsyncClient
as a web spider, however I have noticed that cookies are automatically persisted and there's no easy way to disable this. My workaround has been to subclass python'shttp.cookiejar.CookieJar
like so:Would it be possible to:
Client
/AsyncClient
orNullCookieJar
inhttpx
as a utility class?Thanks!
The text was updated successfully, but these errors were encountered: