-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Cookies aren't being set when sending a HTTP 302. #5181
Comments
@alanwguo I think you shouldn't raise the response. You should return it. async def index(request: web.Request) -> web.Response:
resp = web.HTTPFound("/")
resp.set_cookie("anyscale-token", token)
return resp |
Raising should also work, like in other frameworks. |
I've written the test to reproduce this issue: async def test_httpfound_cookies_302(aiohttp_client):
async def handler(_):
resp = web.HTTPFound("/")
resp.set_cookie("my-cookie", "cookie-value")
return resp
app = web.Application()
app.router.add_get("/", handler)
client = await aiohttp_client(app)
resp = await client.get("/")
assert "my-cookie" in resp.cookies And I've got the following error: Traceback (most recent call last):
File "/home/dmitry/Sources/aiohttp/aiohttp/web_protocol.py", line 456, in _handle_request
resp = await self._request_handler(request)
File "/home/dmitry/Sources/aiohttp/aiohttp/web_app.py", line 348, in _handle
resp = await handler(request)
File "/home/dmitry/Sources/aiohttp/tests/test_web_functional.py", line 1917, in handler
resp.set_cookie("my-cookie", "cookie-value")
AttributeError: 'HTTPFound' object has no attribute 'set_cookie' |
Looks like related to #4277 |
It's an exception, not a response object, why would you expect response methods on it to exist? |
Maybe you are right about #4277 |
If it works correctly for you in aiohttp <3.7, then I'm pretty sure my fix will resolve the issue for you in 3.7 once merged. |
@Dreamsorcerer as far as I understood your PR is merged to 3.8, but not to 3.7. |
Yes, the merge target got changed, so 3.8 now. |
🐞 Describe the bug
This a repeat of the issue described here:
#3700
When setting a cookie and responding with an HTTP redirect, the Set-Cookie header is not set in the response.
💡 To Reproduce
💡 Expected behavior
expect to see Set-Cookie header set
📋 Your version of the Python
📋 Your version of the aiohttp/yarl/multidict distributions
📋 Additional context
The text was updated successfully, but these errors were encountered: