Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#16632 closed Bug (fixed)

204 (No Content) responses without content-type crashes django if UA is Internet Explorer

Reported by: juan@… Owned by: Aymeric Augustin
Component: HTTP handling Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

A HTTP 204 response (no content) doesn't return an entity-body in the request, but Django is forced to include a content-type header because of .../django/http/utils.py fix_IE_for_vary that expects that header to be present.

Let's say we have a HttpResponse subclass like the following:

from django.http import HttpResponse

class HttpEmptyResponse(HttpResponse):
    """
    Special HTTP reponse with no content, just headers.

    The content operations are ignored.
    """
    def __init__(self, content='', mimetype=None, status=None, content_type=None):
        super(HttpEmptyResponse, self).__init__(status=204)

        # although we don't say a content-type, base class sets a
        # default one -- remove it, we're not returning content
        if 'content-type' in self._headers:
            del self._headers['content-type']

    def _set_content(self, value):
        pass

    def _get_content(self, value):
        pass

Django crashes if the UA is not Internet Explorer, otherwise it works perfectly.

References:

Attachments (2)

16632.patch (566 bytes ) - added by Aymeric Augustin 13 years ago.
16632.diff (2.7 KB ) - added by kenth 13 years ago.
patch with tests

Download all attachments as: .zip

Change History (8)

comment:1 by juan@…, 13 years ago

Django crashes if the UA is not Internet Explorer, otherwise it works perfectly.

Sorry for that!

comment:2 by Aymeric Augustin, 13 years ago

Has patch: set
Needs tests: set
Triage Stage: UnreviewedAccepted

by Aymeric Augustin, 13 years ago

Attachment: 16632.patch added

by kenth, 13 years ago

Attachment: 16632.diff added

patch with tests

comment:3 by kenth, 13 years ago

Needs tests: unset

Added tests to confirm bug & patch.

comment:4 by Aymeric Augustin, 13 years ago

Owner: changed from nobody to Aymeric Augustin

comment:5 by Aymeric Augustin, 13 years ago

Resolution: fixed
Status: newclosed

In [17196]:

Fixed #16632 -- Crash on responses without Content-Type with IE. Thanks juan for the report and kenth for the patch.

comment:6 by Aymeric Augustin, 13 years ago

In [17198]:

[1.3.X] Fixed #16632 -- Crash on responses without Content-Type with IE. Backport of r17196.

Note: See TracTickets for help on using tickets.
Back to Top