mirror of
https://github.com/django/django.git
synced 2025-07-04 01:39:20 +00:00
[soc2009/http-wsgi-improvements] Change the setting name to SENDFILE_HEADER and update docs. Refs #2131.
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/http-wsgi-improvements@11327 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
76fdeaf720
commit
019d20a465
@ -242,7 +242,7 @@ MEDIA_URL = ''
|
||||
# req.sendfile.
|
||||
# Examples: 'X-Sendfile' (lighttpd & Cherokee with FastCGI/SCGI, Apache with mod_xsendfile),
|
||||
# 'X-Accel-Redirect' (nginx)
|
||||
HTTPRESPONSE_SENDFILE_HEADER = None
|
||||
SENDFILE_HEADER = None
|
||||
|
||||
# List of upload handler classes to be applied in order.
|
||||
FILE_UPLOAD_HANDLERS = (
|
||||
|
@ -204,9 +204,9 @@ class ModPythonHandler(BaseHandler):
|
||||
req.sendfile(response.sendfile_filename)
|
||||
else:
|
||||
# If we are using a header to do sendfile, set the header and send empty content
|
||||
if settings.RESPONSE_SENDFILE_HEADER:
|
||||
if settings.SENDFILE_HEADER:
|
||||
response.set_empty_content()
|
||||
response[settings.HTTPRESPONSE_SENDFILE_HEADER] = response.sendfile_filename
|
||||
response[settings.SENDFILE_HEADER] = response.sendfile_filename
|
||||
for chunk in response:
|
||||
req.write(chunk)
|
||||
return 0 # mod_python.apache.OK
|
||||
|
@ -243,10 +243,9 @@ class WSGIHandler(base.BaseHandler):
|
||||
|
||||
if isinstance(response, http.HttpResponseSendFile):
|
||||
filename = response.sendfile_filename
|
||||
if settings.HTTPRESPONSE_SENDFILE_HEADER:
|
||||
if settings.SENDFILE_HEADER:
|
||||
response.set_empty_content()
|
||||
response_headers.append((settings.HTTPRESPONSE_SENDFILE_HEADER,
|
||||
filename))
|
||||
response_headers.append((settings.SENDFILE_HEADER, filename))
|
||||
elif 'wsgi.file_wrapper' in environ:
|
||||
filelike = open(filename, 'rb')
|
||||
return environ['wsgi.file_wrapper'](filelike,
|
||||
|
@ -447,7 +447,7 @@ class HttpResponseSendFile(HttpResponse):
|
||||
self.block_size = block_size
|
||||
self['Content-Disposition'] = ('attachment; filename=%s' %
|
||||
os.path.basename(path_to_file))
|
||||
if not settings.HTTPRESPONSE_SENDFILE_HEADER and os.path.exists(path_to_file):
|
||||
if not settings.SENDFILE_HEADER and os.path.exists(path_to_file):
|
||||
self['Content-Length'] = str(os.path.getsize(path_to_file))
|
||||
self._empty_content = False
|
||||
|
||||
|
@ -52,7 +52,7 @@ How the server treats the path varies. For example, on nginx, the root of the pa
|
||||
sent through :func:`~django.http.HttpResponseSendFile` is defined inside its configuration file. However,
|
||||
in most other instances it is treated as the root of the server's file system.
|
||||
|
||||
The header used is defined by the setting :setting:`HTTPRESPONSE_SENDFILE_HEADER`. If it is
|
||||
The header used is defined by the setting :setting:`SENDFILE_HEADER`. If it is
|
||||
left as a default, the fallback method will be used. Otherwise, it should be set as a
|
||||
string containing the header used by the server.
|
||||
|
||||
@ -63,7 +63,7 @@ How to use HttpResponseSendFile with Apache
|
||||
Apache supports efficient file transfer using ``mod_xsendfile_``. Once this module is in
|
||||
place, add the following line to ``settings.py``::
|
||||
|
||||
HTTPRESPONSE_SENDFILE_HEADER = "X-Sendfile"
|
||||
SENDFILE_HEADER = "X-Sendfile"
|
||||
|
||||
This will inform :func:`~django.http.HttpResponseSendFile` that it should allow the server to handle serving
|
||||
the file passed to it.
|
||||
@ -89,7 +89,7 @@ For further information about lighttpd, see `documentation of lighttpd's configu
|
||||
|
||||
Add the following line to ``settings.py``::
|
||||
|
||||
HTTPRESPONSE_SENDFILE_HEADER = "X-Sendfile"
|
||||
SENDFILE_HEADER = "X-Sendfile"
|
||||
|
||||
|
||||
How to use HttpResponseSendFile with Cherokee
|
||||
@ -105,7 +105,7 @@ Cherokee`_.
|
||||
|
||||
Add the following line to ``settings.py``::
|
||||
|
||||
HTTPRESPONSE_SENDFILE_HEADER = "X-Sendfile"
|
||||
SENDFILE_HEADER = "X-Sendfile"
|
||||
|
||||
Then, follow the directions under General Use, above.
|
||||
|
||||
@ -127,5 +127,5 @@ To enable its use in nginx_, follow the directions in `nginx's documentation for
|
||||
|
||||
Add the following line to ``settings.py``::
|
||||
|
||||
HTTPRESPONSE_SENDFILE_HEADER = "X-Accel-Redirect"
|
||||
SENDFILE_HEADER = "X-Accel-Redirect"
|
||||
|
||||
|
@ -585,7 +585,7 @@ live in :mod:`django.http`.
|
||||
optionally, the file's content type and block size hint for handlers that
|
||||
need it.
|
||||
|
||||
If the setting ``HTTPRESPONSE_SENDFILE_HEADER`` is overridden (default None),
|
||||
If the setting :setting:`SENDFILE_HEADER` is overridden (default None),
|
||||
HttpResponseSendFile will return that response header set as the file name given.
|
||||
If the file is unavailable, no content will be returned. Since certain servers
|
||||
do not allow direct access to the file system, it is not feasible to verify
|
||||
@ -595,8 +595,7 @@ live in :mod:`django.http`.
|
||||
must be controlled, and performs no verification of a file's existence in most
|
||||
cases.
|
||||
|
||||
Note that response middleware will be bypassed if you use
|
||||
:class:`HttpResponseSendFile`.
|
||||
**Note:** Response middleware is bypassed by HttpResponseSendFile.
|
||||
|
||||
.. class:: HttpResponseRedirect
|
||||
|
||||
|
@ -835,6 +835,21 @@ link). This is only used if ``CommonMiddleware`` is installed (see
|
||||
|
||||
.. setting:: SERIALIZATION_MODULES
|
||||
|
||||
SENDFILE_HEADER
|
||||
-----------------------------
|
||||
|
||||
Default: ``None``
|
||||
|
||||
If not ``None``, this defines the header that an :func:`~django.http.HttpResponseSendFile`
|
||||
filename is put into, such as ``X-SendFile``. If it is set, the response's content is
|
||||
blank, and the responsibility to send the file is left to the server.
|
||||
|
||||
If ``None``, and the handler does not do anything special for :func:`~django.http.HttpResponseSendFile`,
|
||||
then :func:`~django.http.HttpResponseSendFile` will behave like :func:`~django.http.HttpResponse`,
|
||||
but ensure that the file gets closed.
|
||||
|
||||
.. setting:: SENDFILE_HEADER
|
||||
|
||||
SERIALIZATION_MODULES
|
||||
---------------------
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user