From 664021a9b7fcfe4e2350387c19356b5895842962 Mon Sep 17 00:00:00 2001 From: Chris McKenzie Date: Mon, 4 Aug 2014 10:49:34 -0400 Subject: [PATCH] add content_type query param override --- rest_framework/request.py | 13 +++++++++++-- rest_framework/settings.py | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/rest_framework/request.py b/rest_framework/request.py index 40467c03d..3fb60d806 100644 --- a/rest_framework/request.py +++ b/rest_framework/request.py @@ -116,6 +116,7 @@ class Request(object): _METHOD_PARAM = api_settings.FORM_METHOD_OVERRIDE _CONTENT_PARAM = api_settings.FORM_CONTENT_OVERRIDE _CONTENTTYPE_PARAM = api_settings.FORM_CONTENTTYPE_OVERRIDE + _URL_CONTENTTYPE_PARAM = api_settings.URL_CONTENTTYPE_OVERRIDE def __init__(self, request, parsers=None, authenticators=None, negotiator=None, parser_context=None): @@ -271,8 +272,9 @@ class Request(object): Sets the method and content_type, and then check if they've been overridden. """ - self._content_type = self.META.get('HTTP_CONTENT_TYPE', - self.META.get('CONTENT_TYPE', '')) + self._content_type = self.QUERY_PARAMS.get( + self._URL_CONTENTTYPE_PARAM, self.META.get('HTTP_CONTENT_TYPE', + self.META.get('CONTENT_TYPE', ''))) self._perform_form_overloading() @@ -336,6 +338,13 @@ class Request(object): self._stream = BytesIO(self._data[self._CONTENT_PARAM].encode(self.parser_context['encoding'])) self._data, self._files = (Empty, Empty) + if 'content_type' in self.QUERY_PARAMS and \ + self.QUERY_PARAMS.get('content_type').startswith( + 'application/x-www-form-urlencoded'): + self._stream = BytesIO(self._request.body.encode( + self.parser_context['encoding'])) + self._data, self._files = (Empty, Empty) + def _parse(self): """ Parse the request content, returning a two-tuple of (data, files) diff --git a/rest_framework/settings.py b/rest_framework/settings.py index 38753c968..f15f7f39f 100644 --- a/rest_framework/settings.py +++ b/rest_framework/settings.py @@ -97,6 +97,7 @@ DEFAULTS = { 'FORM_CONTENTTYPE_OVERRIDE': '_content_type', 'URL_ACCEPT_OVERRIDE': 'accept', 'URL_FORMAT_OVERRIDE': 'format', + 'URL_CONTENTTYPE_OVERRIDE': 'content_type', 'FORMAT_SUFFIX_KWARG': 'format', 'URL_FIELD_NAME': 'url',