Skip to content

Commit 3f6aabb

Browse files
author
Ryan P Kilby
committed
Force content_type inclusion in APIRequestFactory
1 parent eb88687 commit 3f6aabb

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

rest_framework/request.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ def _parse(self):
303303
stream = None
304304

305305
if stream is None or media_type is None:
306-
if media_type and not is_form_media_type(media_type):
306+
if media_type and is_form_media_type(media_type):
307307
empty_data = QueryDict('', encoding=self._request._encoding)
308308
else:
309309
empty_data = {}

rest_framework/test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,15 @@ def options(self, path, data=None, format=None, content_type=None, **extra):
227227
data, content_type = self._encode_data(data, format, content_type)
228228
return self.generic('OPTIONS', path, data, content_type, **extra)
229229

230+
def generic(self, method, path, data='',
231+
content_type='application/octet-stream', secure=False, **extra):
232+
# Include the CONTENT_TYPE, regardless of whether or not data is empty.
233+
if content_type is not None:
234+
extra['CONTENT_TYPE'] = content_type
235+
236+
return super(APIRequestFactory, self).generic(
237+
method, path, data, content_type, secure, **extra)
238+
230239
def request(self, **kwargs):
231240
request = super(APIRequestFactory, self).request(**kwargs)
232241
request._dont_enforce_csrf_checks = not self.enforce_csrf_checks

0 commit comments

Comments
 (0)