Skip to content
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

cannot alter response headers from middleware for started StreamResponses #506

Closed
mwfrojdman opened this issue Sep 14, 2015 · 4 comments
Closed
Labels

Comments

@mwfrojdman
Copy link
Contributor

I tried creating a middleware to handle CORS, and I think it would have worked fine in the case of regular Response()s where the handler hasn't called response.start(request).

My handler for Server-sent events (the whole reason I switched to aiohttp btw) however instantiates a StreamResponse object and calls start on it. The headers are flushed out and with the current API, middlewares have no opportunity to do their thing. Actually, they probably never will see the response object, as the client closes the connection before the handler coroutine finishes (in my case it just asyncio.sleeps for 12h).

I have many handlers creating regular Response()s, and for those the middleware solution would work just fine. It would however be nice to be able to rely on middlewares to take care of all requests and replies, without corner cases like now.

@asvetlov
Copy link
Member

Yes, you cannot change response headers for started response (read StreamResponse and WebSocketResponse).
It should be done by signals (not implemented yet, #401 )

@asvetlov
Copy link
Member

#525 is on the middle on solving your issue.

@asvetlov
Copy link
Member

Fixed by #562

@lock
Copy link

lock bot commented Oct 29, 2019

This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related bugs.

If you feel like there's important points made in this discussion,
please include those exceprts into that new issue.

@lock lock bot added the outdated label Oct 29, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants