#15353: problem with django.middleware.gzip.GZipMiddleware
--------------------------------------------+-------------------------------
               Reporter:  bispo@…           |         Owner:  nobody         
                 Status:  closed            |     Milestone:                 
              Component:  Django Web site   |       Version:  1.2            
             Resolution:  worksforme        |      Keywords:  middleware gzip
           Triage Stage:  Unreviewed        |     Has patch:  1              
    Needs documentation:  0                 |   Needs tests:  0              
Patch needs improvement:  0                 |  
--------------------------------------------+-------------------------------
Changes (by russellm):

  * status:  new => closed
  * needs_better_patch:  => 0
  * needs_tests:  => 0
  * needs_docs:  => 0
  * resolution:  => worksforme


Old description:

> 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

New description:

 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

--

Comment:

 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.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/15353#comment:1>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to