Code

Opened 3 years ago

Closed 2 years ago

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

Download all attachments as: .zip

Change History (8)

comment:1 Changed 3 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 3 years ago by aaugustin

  • Has patch set
  • Needs tests set
  • Triage Stage changed from Unreviewed to Accepted

Changed 3 years ago by aaugustin

Changed 2 years ago by kenth

patch with tests

comment:3 Changed 2 years ago by kenth

  • Needs tests unset

Added tests to confirm bug & patch.

comment:4 Changed 2 years ago by aaugustin

  • Owner changed from nobody to aaugustin

comment:5 Changed 2 years ago by aaugustin

  • Resolution set to fixed
  • Status changed from new to closed

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 2 years ago by aaugustin

In [17198]:

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.