mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-23 18:13:57 +03:00
Merge pull request #1265 from tomchristie/fix-1196
Remove Content-Type header from empty responses. Fixes #1196
This commit is contained in:
commit
25ac4cd20e
|
@ -44,6 +44,7 @@ You can determine your currently installed version using `pip freeze`:
|
||||||
|
|
||||||
* Add in choices information for ChoiceFields in response to `OPTIONS` requests.
|
* Add in choices information for ChoiceFields in response to `OPTIONS` requests.
|
||||||
* Added `pre_delete()` and `post_delete()` method hooks.
|
* Added `pre_delete()` and `post_delete()` method hooks.
|
||||||
|
* Bugfix: Responses without any content no longer include an HTTP `'Content-Type'` header.
|
||||||
* Bugfix: Correctly handle validation errors in PUT-as-create case, responding with 400.
|
* Bugfix: Correctly handle validation errors in PUT-as-create case, responding with 400.
|
||||||
|
|
||||||
### 2.3.9
|
### 2.3.9
|
||||||
|
|
|
@ -61,6 +61,10 @@ class Response(SimpleTemplateResponse):
|
||||||
assert charset, 'renderer returned unicode, and did not specify ' \
|
assert charset, 'renderer returned unicode, and did not specify ' \
|
||||||
'a charset value.'
|
'a charset value.'
|
||||||
return bytes(ret.encode(charset))
|
return bytes(ret.encode(charset))
|
||||||
|
|
||||||
|
if not ret:
|
||||||
|
del self['Content-Type']
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -64,11 +64,16 @@ class MockView(APIView):
|
||||||
|
|
||||||
|
|
||||||
class MockGETView(APIView):
|
class MockGETView(APIView):
|
||||||
|
|
||||||
def get(self, request, **kwargs):
|
def get(self, request, **kwargs):
|
||||||
return Response({'foo': ['bar', 'baz']})
|
return Response({'foo': ['bar', 'baz']})
|
||||||
|
|
||||||
|
|
||||||
|
class EmptyGETView(APIView):
|
||||||
|
renderer_classes = (JSONRenderer,)
|
||||||
|
|
||||||
|
def get(self, request, **kwargs):
|
||||||
|
return Response(status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
class HTMLView(APIView):
|
class HTMLView(APIView):
|
||||||
renderer_classes = (BrowsableAPIRenderer, )
|
renderer_classes = (BrowsableAPIRenderer, )
|
||||||
|
|
||||||
|
@ -90,6 +95,7 @@ urlpatterns = patterns('',
|
||||||
url(r'^jsonp/nojsonrenderer$', MockGETView.as_view(renderer_classes=[JSONPRenderer])),
|
url(r'^jsonp/nojsonrenderer$', MockGETView.as_view(renderer_classes=[JSONPRenderer])),
|
||||||
url(r'^html$', HTMLView.as_view()),
|
url(r'^html$', HTMLView.as_view()),
|
||||||
url(r'^html1$', HTMLView1.as_view()),
|
url(r'^html1$', HTMLView1.as_view()),
|
||||||
|
url(r'^empty$', EmptyGETView.as_view()),
|
||||||
url(r'^api', include('rest_framework.urls', namespace='rest_framework'))
|
url(r'^api', include('rest_framework.urls', namespace='rest_framework'))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -219,6 +225,16 @@ class RendererEndToEndTests(TestCase):
|
||||||
self.assertEqual(resp.content, RENDERER_B_SERIALIZER(DUMMYCONTENT))
|
self.assertEqual(resp.content, RENDERER_B_SERIALIZER(DUMMYCONTENT))
|
||||||
self.assertEqual(resp.status_code, DUMMYSTATUS)
|
self.assertEqual(resp.status_code, DUMMYSTATUS)
|
||||||
|
|
||||||
|
def test_204_no_content_responses_have_no_content_type_set(self):
|
||||||
|
"""
|
||||||
|
Regression test for #1196
|
||||||
|
|
||||||
|
https://github.com/tomchristie/django-rest-framework/issues/1196
|
||||||
|
"""
|
||||||
|
resp = self.client.get('/empty')
|
||||||
|
self.assertEqual(resp.get('Content-Type', None), None)
|
||||||
|
self.assertEqual(resp.status_code, status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
|
|
||||||
_flat_repr = '{"foo": ["bar", "baz"]}'
|
_flat_repr = '{"foo": ["bar", "baz"]}'
|
||||||
_indented_repr = '{\n "foo": [\n "bar",\n "baz"\n ]\n}'
|
_indented_repr = '{\n "foo": [\n "bar",\n "baz"\n ]\n}'
|
||||||
|
|
Loading…
Reference in New Issue
Block a user