Code

Opened 3 years ago

Closed 3 years ago

#15353 closed (worksforme)

problem with django.middleware.gzip.GZipMiddleware

Reported by: bispo@… Owned by: nobody
Component: *.djangoproject.com Version: 1.2
Severity: Keywords: middleware gzip
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description (last modified by russellm)

In django.middleware.gzip.GZipMiddleware have a bug:

def process_response(self, request, response):
        # It's not worth compressing non-OK or really short responses.
        if response.status_code != 200 or len(response.content) < 200:
            return response

exist response without response.content!

when I use: (in url.py )

(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),

to binary files have a problem, do not exist response.content.

to solver the bug I add 'try' on code:
       try:
        if response.status_code != 200 or len(response.content) < 200:
            return response
       except:
        return response

In my vision the middlewere gzip don't have compress binary, because the browser is incompatible

Attachments (0)

Change History (1)

comment:1 Changed 3 years ago by russellm

  • Description modified (diff)
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to worksforme
  • Status changed from new to closed

Please use preview when submitting code samples.

As for the bug itself: response *always* has a 'content' attribute. That's part of the basic contract of HttpResponse. The static serve view works fine for me with binary content -- because it doesn't just dump a file, it constructs a HttpResponse to contain the file content. I can't reproduce the problem as described, and what you're describing doesn't make a whole lot of sense.

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.