From dd7a9b62316d57406a46235ff2acc25cff2081b6 Mon Sep 17 00:00:00 2001 From: Dennis Hotson Date: Fri, 10 Oct 2014 11:42:05 +1100 Subject: [PATCH] [HttpFoundation] Allow Cache-Control headers on StreamedResponse --- .../Component/HttpFoundation/StreamedResponse.php | 10 ---------- .../HttpFoundation/Tests/StreamedResponseTest.php | 11 +++++++++-- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/StreamedResponse.php b/src/Symfony/Component/HttpFoundation/StreamedResponse.php index 4be9f48c9c..38986e8aa7 100644 --- a/src/Symfony/Component/HttpFoundation/StreamedResponse.php +++ b/src/Symfony/Component/HttpFoundation/StreamedResponse.php @@ -79,16 +79,6 @@ class StreamedResponse extends Response $this->callback = $callback; } - /** - * {@inheritdoc} - */ - public function prepare(Request $request) - { - $this->headers->set('Cache-Control', 'no-cache'); - - return parent::prepare($request); - } - /** * {@inheritdoc} * diff --git a/src/Symfony/Component/HttpFoundation/Tests/StreamedResponseTest.php b/src/Symfony/Component/HttpFoundation/Tests/StreamedResponseTest.php index 0dfe651600..940f17cac4 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/StreamedResponseTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/StreamedResponseTest.php @@ -34,7 +34,6 @@ class StreamedResponseTest extends \PHPUnit_Framework_TestCase $this->assertEquals('1.1', $response->getProtocolVersion()); $this->assertNotEquals('chunked', $response->headers->get('Transfer-Encoding'), 'Apache assumes responses with a Transfer-Encoding header set to chunked to already be encoded.'); - $this->assertEquals('no-cache, private', $response->headers->get('Cache-Control')); } public function testPrepareWith10Protocol() @@ -47,7 +46,6 @@ class StreamedResponseTest extends \PHPUnit_Framework_TestCase $this->assertEquals('1.0', $response->getProtocolVersion()); $this->assertNull($response->headers->get('Transfer-Encoding')); - $this->assertEquals('no-cache, private', $response->headers->get('Cache-Control')); } public function testPrepareWithHeadRequest() @@ -58,6 +56,15 @@ class StreamedResponseTest extends \PHPUnit_Framework_TestCase $response->prepare($request); } + public function testPrepareWithCacheHeaders() + { + $response = new StreamedResponse(function () { echo 'foo'; }, 200, array('Cache-Control' => 'max-age=600, public')); + $request = Request::create('/', 'GET'); + + $response->prepare($request); + $this->assertEquals('max-age=600, public', $response->headers->get('Cache-Control')); + } + public function testSendContent() { $called = 0;