#6027: FileWrapper iterator drained by GzipMiddleware before content can be
returned
-------------------------------------+------------------------------
Reporter: volsung@… | Owner: nobody
Type: Bug | Status: new
Milestone: | Component: Core (Other)
Version: SVN | Severity: Normal
Resolution: | Keywords:
Triage Stage: Accepted | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+------------------------------
Comment (by snyderra@…):
Here is a flow of the problem[[BR]]
gzip middleware calls response.content. this is a property that does a
!''.join(self._container)[[BR]]
this causes the iterator to be called which drains the iterator.
the quick fix is to make the following class and use it. Hopefully the
filelike object you are using has a seek method
{{{
class FixedFileWrapper(FileWrapper):
def __iter__(self):
self.filelike.seek(0)
return self
}}}
a more proper fix would be to implement the following in HTTPResponse
{{{
def __len__(self):
if 'Content-Length' in self._headers:
return int(self._headers.get('Content-
Length',len(self._container)))
}}}
This way the gzip middleware could just do a len(response) and optionally
the !FileWrapper class could also have a !__len!__ method
--
Ticket URL: <https://code.djangoproject.com/ticket/6027#comment:10>
Django <https://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.