Only honor X-HTTP-Method-Override for POST requests.

This commit is contained in:
Tom Christie 2013-03-12 20:49:20 +00:00
parent 716d86863f
commit 377dc2cda2
2 changed files with 10 additions and 9 deletions

View File

@ -21,11 +21,9 @@ For example, given the following form:
## HTTP header based method overriding
REST framework also supports method overriding via the `X-HTTP-Method-Override`
header. This is useful if you are working with non-form content such as
JSON and are working with an older web server and/or hosting provider
(e.g. [Amazon Web Services ELB][aws_elb]) that doesn't recognise particular
HTTP methods such as `PATCH`.
REST framework also supports method overriding via the semi-standard `X-HTTP-Method-Override` header. This can be useful if you are working with non-form content such as JSON and are working with an older web server and/or hosting provider that doesn't recognise particular HTTP methods such as `PATCH`. For example [Amazon Web Services ELB][aws_elb].
To use it, make a `POST` request, setting the `X-HTTP-Method-Override` header.
For example, making a `PATCH` request via `POST` in jQuery:

View File

@ -233,11 +233,14 @@ class Request(object):
self.META.get('CONTENT_TYPE', ''))
self._perform_form_overloading()
if not _hasattr(self, '_method'):
# Method wasn't overloaded by hidden form element, so look for
# method override in header. If not present default to raw HTTP method
self._method = self.META.get('HTTP_X_HTTP_METHOD_OVERRIDE',
self._request.method)
self._method = self._request.method
if self._method == 'POST':
# Allow X-HTTP-METHOD-OVERRIDE header
self._method = self.META.get('HTTP_X_HTTP_METHOD_OVERRIDE',
self._method)
def _load_stream(self):
"""