From a79991f44aac63950c6406545ef9461cfb3fbc7c Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 24 Oct 2016 16:19:10 +0200 Subject: [PATCH] Fix edge case with StreamedResponse where headers are sent twice --- .../HttpFoundation/StreamedResponse.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Symfony/Component/HttpFoundation/StreamedResponse.php b/src/Symfony/Component/HttpFoundation/StreamedResponse.php index 4b936a150e..8274dc43a0 100644 --- a/src/Symfony/Component/HttpFoundation/StreamedResponse.php +++ b/src/Symfony/Component/HttpFoundation/StreamedResponse.php @@ -28,6 +28,7 @@ class StreamedResponse extends Response { protected $callback; protected $streamed; + private $headersSent; /** * Constructor. @@ -44,6 +45,7 @@ class StreamedResponse extends Response $this->setCallback($callback); } $this->streamed = false; + $this->headersSent = false; } /** @@ -75,6 +77,22 @@ class StreamedResponse extends Response $this->callback = $callback; } + /** + * {@inheritdoc} + * + * This method only sends the headers once. + */ + public function sendHeaders() + { + if ($this->headersSent) { + return; + } + + $this->headersSent = true; + + parent::sendHeaders(); + } + /** * {@inheritdoc} *