diff --git a/docs/topics/browser-enhancements.md b/docs/topics/browser-enhancements.md index 8b1914231..ce07fe95b 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 f26d934d7..ffbbab338 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): """