Skip to content

Commit 615a7b3

Browse files
committed
[#2416] Proofreading the new BinaryFileResponse and talking about X-Sendfile
1 parent 71de41a commit 615a7b3

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

book/controller.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ headers and content that's sent back to the client::
731731
- For JSON, there is :class:`Symfony\\Component\\HttpFoundation\\JsonResponse`.
732732
See :ref:`component-http-foundation-json-response`.
733733
- For files, there is :class:`Symfony\\Component\\HttpFoundation\\BinaryFileResponse`.
734-
See :ref:`component-http-foundation-serving-files
734+
See :ref:`component-http-foundation-serving-files`.
735735

736736
.. index::
737737
single: Controller; Request object

components/http_foundation/introduction.rst

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,15 @@ Alternatively, if you are serving a static file, you can use a
439439
$response = new BinaryFileResponse($file);
440440

441441
The ``BinaryFileResponse`` will automatically handle ``Range`` and
442-
``If-Range`` headers from the request. You can also set the ``Content-Type``
443-
of the sent file, or change its ``Content-Disposition``::
442+
``If-Range`` headers from the request. It also supports ``X-Sendfile``
443+
(see for `Nginx`_ and `Apache`_). To make use of it, you need to determine
444+
whether or not the ``X-Sendfile-Type`` header should be trusted and call
445+
:method:`Symfony\\Component\\HttpFoundation\\BinaryFileResponse::trustXSendfileTypeHeader`
446+
if it should::
447+
448+
$response::trustXSendfileTypeHeader();
449+
450+
You can still set the ``Content-Type`` of the sent file, or change its ``Content-Disposition``::
444451

445452
$response->headers->set('Content-Type', 'text/plain')
446453
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, 'filename.txt');
@@ -496,3 +503,5 @@ Session
496503
The session information is in its own document: :doc:`/components/http_foundation/sessions`.
497504

498505
.. _Packagist: https://packagist.org/packages/symfony/http-foundation
506+
.. _Nginx: http://wiki.nginx.org/XSendfile
507+
.. _Apache: https://tn123.org/mod_xsendfile/

0 commit comments

Comments
 (0)