Opened 5 years ago

Closed 5 years ago

Last modified 5 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 5 years ago.
16632.diff (2.7 KB) - added by kenth 5 years ago.
patch with tests

Download all attachments as: .zip

Change History (8)

comment:1 Changed 5 years ago by juan@…

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

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

Sorry for that!

comment:2 Changed 5 years ago by Aymeric Augustin

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

Changed 5 years ago by Aymeric Augustin

Attachment: 16632.patch added

Changed 5 years ago by kenth

Attachment: 16632.diff added

patch with tests

comment:3 Changed 5 years ago by kenth

Needs tests: unset

Added tests to confirm bug & patch.

comment:4 Changed 5 years ago by Aymeric Augustin

Owner: changed from nobody to Aymeric Augustin

comment:5 Changed 5 years ago by Aymeric Augustin

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 Changed 5 years ago by Aymeric Augustin

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