Add a require_safe decorator for views to accept GET or HEAD
|Reported by:||Aymeric Augustin||Owned by:||nobody|
|Cc:||Tom Christie, 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)
comment:1 Changed 6 years ago by
|Patch needs improvement:||unset|