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

Feature request: in the server, modifying the response headers after they have been sent should raise #3231

Open
arthurdarcet opened this issue Aug 31, 2018 · 5 comments

Comments

@arthurdarcet
Copy link
Contributor

Simple feature: I think after the response has been prepared (ie after the headers are sent back to the client), the Response.headers object should become a read-only dict (ie a CIMultiDictProxy), so that it cannot be modified.

Would you accept a patch doing this?

@asvetlov
Copy link
Member

asvetlov commented Sep 1, 2018

I have no strong opinion.
It makes sense but mutation of attribute type sounds weird from type hinting perspective.

@arthurdarcet
Copy link
Contributor Author

I agree that the type should stay the same.

Ideally, the response.headers object should be a CIMultiDict, but it should raise exceptions when it is mutated after the headers are sent. Replacing the object with a CIMultiDictProxy achieves that, but will give poor error messages to the users, and breaks the type-hinting. Would you prefer an approach that set headers to be a ResponseHeader object, extending CIMultiDict but with an option to raise an explicit error when trying to use __setitem__, add, pop, popall, … The downside to this is that we will have to maintain here the list of "mutating methods" that are forbidden after the response is sent

@asvetlov
Copy link
Member

asvetlov commented Sep 4, 2018

Let me sleep on it.

@asvetlov
Copy link
Member

asvetlov commented Sep 4, 2018

As an option, we can use multidict's version number: store it on headers sending and compare with the current value on exiting from web-handler.
If numbers are different -- raise a warning or something like this.
Not ideal (no stack trace pointing on the bad code) but better than nothing.

@arthurdarcet
Copy link
Contributor Author

arthurdarcet commented Sep 4, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants