aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Christie2013-03-12 20:49:20 +0000
committerTom Christie2013-03-12 20:49:20 +0000
commit377dc2cda2c3a7aa02f5d761631f73c58745ed9d (patch)
treea806ac1140107d3f139e7da9cec786d632f88a7d
parent716d86863f022e7dd4b9b71ecde1d908f30bdf60 (diff)
downloaddjango-rest-framework-377dc2cda2c3a7aa02f5d761631f73c58745ed9d.tar.bz2
Only honor X-HTTP-Method-Override for POST requests.
-rw-r--r--docs/topics/browser-enhancements.md8
-rw-r--r--rest_framework/request.py11
2 files changed, 10 insertions, 9 deletions
diff --git a/docs/topics/browser-enhancements.md b/docs/topics/browser-enhancements.md
index 8b191423..ce07fe95 100644
--- a/docs/topics/browser-enhancements.md
+++ b/docs/topics/browser-enhancements.md
@@ -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:
diff --git a/rest_framework/request.py b/rest_framework/request.py
index f26d934d..ffbbab33 100644
--- a/rest_framework/request.py
+++ b/rest_framework/request.py
@@ -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):
"""