diff --git a/django/conf/global_settings.py b/django/conf/global_settings.py index 22b2b6e10a..f28843c6e5 100644 --- a/django/conf/global_settings.py +++ b/django/conf/global_settings.py @@ -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 = ( diff --git a/django/core/handlers/modpython.py b/django/core/handlers/modpython.py index 338eb3abb1..ae609fdba6 100644 --- a/django/core/handlers/modpython.py +++ b/django/core/handlers/modpython.py @@ -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 diff --git a/django/core/handlers/wsgi.py b/django/core/handlers/wsgi.py index 359d4b5425..02ef17ed03 100644 --- a/django/core/handlers/wsgi.py +++ b/django/core/handlers/wsgi.py @@ -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, diff --git a/django/http/__init__.py b/django/http/__init__.py index 55592d628f..7f96e8309b 100644 --- a/django/http/__init__.py +++ b/django/http/__init__.py @@ -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 diff --git a/docs/howto/response-sendfile.txt b/docs/howto/response-sendfile.txt index 2999261993..a333c26dca 100644 --- a/docs/howto/response-sendfile.txt +++ b/docs/howto/response-sendfile.txt @@ -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" diff --git a/docs/ref/request-response.txt b/docs/ref/request-response.txt index 3db6a680eb..ae23c3a507 100644 --- a/docs/ref/request-response.txt +++ b/docs/ref/request-response.txt @@ -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 diff --git a/docs/ref/settings.txt b/docs/ref/settings.txt index e8c673d995..0f0fd6802d 100644 --- a/docs/ref/settings.txt +++ b/docs/ref/settings.txt @@ -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 ---------------------