Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Delete Content-Type header from HttpAccepted (204 No Content) responses #111

Open
wants to merge 2 commits into from

5 participants

Mikhail Korobov Juan J. Martínez Issac Kelly Chris Adams Daniel Lindsley
Mikhail Korobov

This header can be returned with HttpAccepted according to rfc2616, but it is useless (so removing it will slightly decrease bandwidth usage) and lint tools can complain about this header (e.g. Ian Bicking's wsgi lint middleware included in WebTest raises AssertionError for 204 responses with Content-Type header).

kmike added some commits
Mikhail Korobov kmike Correct python_dateutil versions in setup.py and requirements.txt.
python_dateutil 2.0 was released some time ago and it is python3 only leading to weird errors while using django-tastypie.
97835c6
Mikhail Korobov kmike Delete Content-Type header from HttpAccepted (204 No Content) respons…
…e because this response can't have content.

This header can be returned with HttpAccepted according to rfc2616, but it is useless (so removing it will slightly decrease bandwidth usage) and lint tools can complain about this header (e.g. Ian Bicking's wsgi lint middleware included in WebTest raises AssertionError for 204 responses with Content-Type header).
1d7dd81
Juan J. Martínez

fix_IE_for_vary from django/http/utils.py will crash if there's no content-type header.

Django 1.3 here.

Issac Kelly
Collaborator

So, our tests pass, but I can see the exact case where in 1.3 this would break IE based clients.

The correct patch for the issue is below, but we can't include it until we drop 1.3 support.

diff --git a/tastypie/http.py b/tastypie/http.py
index 436f9df..4b73881 100644
--- a/tastypie/http.py
+++ b/tastypie/http.py
@@ -25,6 +25,10 @@ class HttpAccepted(HttpResponse):
 class HttpNoContent(HttpResponse):
     status_code = 204

+    def __init__(self, *args, **kwargs):
+        super(HttpNoContent, self).__init__(*args, **kwargs)
+        del self['Content-Type']
+

 class HttpMultipleChoices(HttpResponse):
     status_code = 300
Chris Adams
Collaborator

@issackelly Any objections to merging this now that Django 1.3 is no longer supported?

Chris Adams acdha referenced this pull request from a commit in acdha/django-tastypie
Chris Adams acdha Suppress Content-Type header on HTTP 204 (see #111)
This is a tidied up version of the patch in #111 with tests
6295d0a
Daniel Lindsley
Owner

(Stands in for @issackelly) @acdha Yeah, let's get this merged.

Issac Kelly
Collaborator

Sorry I didn't see this, :shipit:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 2, 2011
  1. Mikhail Korobov

    Correct python_dateutil versions in setup.py and requirements.txt.

    kmike authored
    python_dateutil 2.0 was released some time ago and it is python3 only leading to weird errors while using django-tastypie.
  2. Mikhail Korobov

    Delete Content-Type header from HttpAccepted (204 No Content) respons…

    kmike authored
    …e because this response can't have content.
    
    This header can be returned with HttpAccepted according to rfc2616, but it is useless (so removing it will slightly decrease bandwidth usage) and lint tools can complain about this header (e.g. Ian Bicking's wsgi lint middleware included in WebTest raises AssertionError for 204 responses with Content-Type header).
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 6 deletions.
  1. +1 −1  requirements.txt
  2. +3 −3 setup.py
  3. +6 −2 tastypie/http.py
2  requirements.txt
View
@@ -1,5 +1,5 @@
Django>=1.0.0
mimeparse>=0.1.3
-python-dateutil
+python-dateutil==1.5
lxml
PyYAML
6 setup.py 100644 → 100755
View
@@ -18,11 +18,11 @@
},
requires=[
'mimeparse',
- 'python_dateutil',
+ 'python_dateutil(>=1.5, < 2.0)',
],
install_requires=[
'mimeparse',
- 'python_dateutil',
+ 'python_dateutil >= 1.5, < 2.0',
],
classifiers=[
'Development Status :: 4 - Beta',
@@ -34,4 +34,4 @@
'Programming Language :: Python',
'Topic :: Utilities'
],
-)
+)
8 tastypie/http.py
View
@@ -6,12 +6,12 @@
class HttpCreated(HttpResponse):
status_code = 201
-
+
def __init__(self, *args, **kwargs):
if 'location' in kwargs:
location = kwargs['location']
del(kwargs['location'])
-
+
super(HttpCreated, self).__init__(*args, **kwargs)
self['Location'] = location
@@ -19,6 +19,10 @@ def __init__(self, *args, **kwargs):
class HttpAccepted(HttpResponse):
status_code = 204
+ def __init__(self, *args, **kwargs):
+ super(HttpAccepted, self).__init__(*args, **kwargs)
+ del self['Content-Type']
+
class HttpMultipleChoices(HttpResponse):
status_code = 300
Something went wrong with that request. Please try again.