Add a require_safe decorator for views to accept GET or HEAD
|Reported by:||aaugustin||Owned by:||nobody|
|Cc:||tomchristie, leidel@…||Triage Stage:||Ready for checkin|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
It is a good practice to reject POST requests on views that are not intended to process them. Django provides the require_GET decorator for this purpose.
Although browsers only implement GET and POST methods, other software such as link checkers uses HEAD requests. Views protected by require_GET will (obviously) reject such requests with "405 Method Not Allowed". I've encountered the problem with the "Check My Links" extension for Google Chrome.
However, RFC2616 says that "The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response." Django already enforces this behavior by stripping the body of the responses to HEAD requests. So I think that in most cases, it makes more sense to accept GET and HEAD than only GET.
That is why I'm proposing a "require_safe" decorator for this purpose.
Change History (13)
Changed 4 years ago by aaugustin
comment:1 Changed 4 years ago by aaugustin
- Has patch set
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset