﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
6543	serving files/iterated content with setting.USE_ETAGS = True	pcicman	nobody	"It seems there's a bug in '''django.core.servers.basehttp.FileWrapper'''. FileWraper should do seek(0) before new interation.
Problem comes only with using Etags and this line (in django.middleware.common.CommonMiddleware):


{{{
etag = md5.new(response.content).hexdigest()
}}}


this calls code in HttpResponse object:


{{{
def _get_content(self):
        if self.has_header('Content-Encoding'):
            return ''.join(self._container)
        return smart_str(''.join(self._container), self._charset)
}}}


and join iterates over FileWrapper object:


{{{
def next(self):
        data = self.filelike.read(self.blksize)
        if data:
            return data
        raise StopIteration

}}}

but there's no return back to file begining. md5 Makes first iteration, and next iteration is called when response gets converted to string and set back to client.


== Solution can probably be: ==

{{{
def next(self):
        data = self.filelike.read(self.blksize)
        if data:
            return data
            self.filelike.seek(0)
        raise StopIteration
}}}


== Better solution ==
Add some temporary cache variable to HttpResponse object, so content gets iterated only once (i think this can be much more faster solution, shorter exec time).
In this case there's no seek(0) required."	Bug	closed	Core (Other)	dev	Normal	duplicate	USE_ETAGS etag file zip md5 iterator		Accepted	1	0	1	0	0	0
