-
Notifications
You must be signed in to change notification settings - Fork 887
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
Pyramid 2.0 could restrict the request methods by default in add_view
, view_config
.
#2796
Comments
#1484 is tangentially related. |
So just as an FYI I've implemented CORS using a global approach here: https://gist.github.com/mmerickel/1afaf64154b335b596e4 Another option is something similar to what we did with CSRF checks where we add something like I don't think this is compelling enough to switch the defaults, but that's my 2 cents right now. |
If you set I on all of my views set With your proposed changes, then users can't have a single view that handles verbs and then have a large if statement that switches on the request method. |
It was just an option; my point is that even though explicit is better than implicit, people write software so that "no request method" means
so in the end the "any request method" views are almost always not very correct. |
The biggest issue here is that the implementation is not near as easy as you probably think it is right now. A naive approach will conflict with #1863 in which a default view with |
The I did a longer write up in one of those issues before... |
I haven't yet seen a compelling reason for such a drastic change to |
The thing is now it is pretty much impossible to do the sane things. The implicit behaviour is dangerous and people do not realize it works like that. It would be better if the |
405 for unsupported views is almost impossible in Pyramid to implement, especially if you are using something like traversal, due to the way that view matching is allowed to walk up the traversal tree to find a potential match. We can't say "sure, if you changed your request method for the request it may succeed", it's just the nature of the beast. I've spent an awful lot of time trying to reason through and think through how we could add support for 405's, but it is simply not something that Pyramid can reliably do. Things like Cornice and others add it as a later step and handle the 405 themselves, which is possible because they can know whether the request could succeed if the request method was changed. |
I don't mean that Pyramid should necessarily do 405, as it would indeed be quite difficult to work out what would be allowed, as RFC 2616 says that the response "MUST include an Allow header containing a list of valid methods for the requested resource." |
The current behaviour of Pyramid is that by default all views handle all HTTP verbs, unless explicitly stated otherwise. This means that for example CORS preflight OPTIONS requests will trigger lots of inadvertent code etc. As as far as I know no one really wants to respond to OPTIONS with whatever body the view returns, one thing to consider would be that in Pyramid 2.0 the
request_method
would default to('GET', 'POST')
(and includingHEAD
naturally) instead; after all, this is mostly what people think the behaviour would be, unless explicitly excepted otherwise.The text was updated successfully, but these errors were encountered: