mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-04 20:40:14 +03:00
add content_type query param override
This commit is contained in:
parent
57d6e04ff5
commit
664021a9b7
|
@ -116,6 +116,7 @@ class Request(object):
|
||||||
_METHOD_PARAM = api_settings.FORM_METHOD_OVERRIDE
|
_METHOD_PARAM = api_settings.FORM_METHOD_OVERRIDE
|
||||||
_CONTENT_PARAM = api_settings.FORM_CONTENT_OVERRIDE
|
_CONTENT_PARAM = api_settings.FORM_CONTENT_OVERRIDE
|
||||||
_CONTENTTYPE_PARAM = api_settings.FORM_CONTENTTYPE_OVERRIDE
|
_CONTENTTYPE_PARAM = api_settings.FORM_CONTENTTYPE_OVERRIDE
|
||||||
|
_URL_CONTENTTYPE_PARAM = api_settings.URL_CONTENTTYPE_OVERRIDE
|
||||||
|
|
||||||
def __init__(self, request, parsers=None, authenticators=None,
|
def __init__(self, request, parsers=None, authenticators=None,
|
||||||
negotiator=None, parser_context=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
|
Sets the method and content_type, and then check if they've
|
||||||
been overridden.
|
been overridden.
|
||||||
"""
|
"""
|
||||||
self._content_type = self.META.get('HTTP_CONTENT_TYPE',
|
self._content_type = self.QUERY_PARAMS.get(
|
||||||
self.META.get('CONTENT_TYPE', ''))
|
self._URL_CONTENTTYPE_PARAM, self.META.get('HTTP_CONTENT_TYPE',
|
||||||
|
self.META.get('CONTENT_TYPE', '')))
|
||||||
|
|
||||||
self._perform_form_overloading()
|
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._stream = BytesIO(self._data[self._CONTENT_PARAM].encode(self.parser_context['encoding']))
|
||||||
self._data, self._files = (Empty, Empty)
|
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):
|
def _parse(self):
|
||||||
"""
|
"""
|
||||||
Parse the request content, returning a two-tuple of (data, files)
|
Parse the request content, returning a two-tuple of (data, files)
|
||||||
|
|
|
@ -97,6 +97,7 @@ DEFAULTS = {
|
||||||
'FORM_CONTENTTYPE_OVERRIDE': '_content_type',
|
'FORM_CONTENTTYPE_OVERRIDE': '_content_type',
|
||||||
'URL_ACCEPT_OVERRIDE': 'accept',
|
'URL_ACCEPT_OVERRIDE': 'accept',
|
||||||
'URL_FORMAT_OVERRIDE': 'format',
|
'URL_FORMAT_OVERRIDE': 'format',
|
||||||
|
'URL_CONTENTTYPE_OVERRIDE': 'content_type',
|
||||||
|
|
||||||
'FORMAT_SUFFIX_KWARG': 'format',
|
'FORMAT_SUFFIX_KWARG': 'format',
|
||||||
'URL_FIELD_NAME': 'url',
|
'URL_FIELD_NAME': 'url',
|
||||||
|
|
Loading…
Reference in New Issue
Block a user