Support handler optimisations for file downloads
|Reported by:||Owned by:||nobody|
|Cc:||django-ticket-7894@…, piranha@…||Triage Stage:||Design decision needed|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Sometimes a django app wants to return a file in a response. You can currently do this by returning the data or an iterator for the data in the content of an HttpResponse. However WSGI provides an optional mechanism for higher performance file transmission...
...and I imagine mod_python is capable of a similar speed up.
In order to flag to the handler that the response is suitable for this speedup I suggest a new HttpResponseFileWrapper object that wraps a file like object. This response falls back to providing its content via an iterator that reads in block_size (a extra optional parameter) bytes at a time. The speedup mechanism can also use the block_size as a suggestion for reading data from the filelike object.
So for example...
from django.http import HttpResponseFileWrapper def view(request): return HttpResponseFileWrapper(open('foo.pdf'), block_size=8192)
Change History (14)
comment:1 Changed 8 years ago by
|Patch needs improvement:||unset|
comment:6 Changed 8 years ago by
|Triage Stage:||Unreviewed → Design decision needed|