#10627: Middleware using len() on response.content is gobbling generators ----------------------------+----------------------------------------------- Reporter: FunkyBob | Owner: nobody Status: new | Milestone: Component: Core framework | Version: SVN Keywords: middleware | Stage: Unreviewed Has_patch: 1 | ----------------------------+----------------------------------------------- We recently found that a slow view (4 to 5 minutes) was made even worse because we couldn't give a generator to HttpResponse and have it still work.
This turned out to be because two of the built-in middlewares ( gzip and conditional-get ) assume the response.content is a string, and call len(response.content) -- which consumes the generator. Once we bypassed these, the time to first response was seconds, and the entire process ran smoothly. So, attached are two patches to work around this issue: 1. In the case of conditional-get, it skips setting Content-Length header if not response._is_string. 2. In the case of gzip, simply move the Content-Encoding test to the front, so the documentation saying gzip will be skipped on anything with a Content-Encoding header works as expected. -- Ticket URL: <http://code.djangoproject.com/ticket/10627> 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 django-updates@googlegroups.com To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-updates?hl=en -~----------~----~----~----~------~----~------~--~---