From 83c23ca0bea1b10224266fcf7ec58cc2fa52b94a Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Mon, 2 Jan 2012 19:44:42 +0100 Subject: [PATCH 1/2] [streaming] Do not set a Transfer-Encoding header of chunked Apache expects the response to already be in chunked format in that case, which causes it to not deliver the streamed body. If no Content-Length is set on the response, web servers will automatically switch to chunked Transfer-Encoding, and handle the chunking for you. Nginx does not share the issue that apache has, but will add the Content- Length header too. --- src/Symfony/Component/HttpFoundation/StreamedResponse.php | 1 - .../Tests/Component/HttpFoundation/StreamedResponseTest.php | 1 - 2 files changed, 2 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/StreamedResponse.php b/src/Symfony/Component/HttpFoundation/StreamedResponse.php index 503ccef7831d2..5684c3ceedf60 100644 --- a/src/Symfony/Component/HttpFoundation/StreamedResponse.php +++ b/src/Symfony/Component/HttpFoundation/StreamedResponse.php @@ -70,7 +70,6 @@ public function prepare(Request $request) { if ('1.0' != $request->server->get('SERVER_PROTOCOL')) { $this->setProtocolVersion('1.1'); - $this->headers->set('Transfer-Encoding', 'chunked'); } $this->headers->set('Cache-Control', 'no-cache'); diff --git a/tests/Symfony/Tests/Component/HttpFoundation/StreamedResponseTest.php b/tests/Symfony/Tests/Component/HttpFoundation/StreamedResponseTest.php index 308a4651fb528..389e775f97a6d 100644 --- a/tests/Symfony/Tests/Component/HttpFoundation/StreamedResponseTest.php +++ b/tests/Symfony/Tests/Component/HttpFoundation/StreamedResponseTest.php @@ -33,7 +33,6 @@ public function testPrepareWith11Protocol() $response->prepare($request); $this->assertEquals('1.1', $response->getProtocolVersion()); - $this->assertEquals('chunked', $response->headers->get('Transfer-Encoding')); $this->assertEquals('no-cache, private', $response->headers->get('Cache-Control')); } From 7ae93483f9d13931342cb4bc06b27a6598708026 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Mon, 2 Jan 2012 20:21:31 +0100 Subject: [PATCH 2/2] [streaming] Document and test that Transfer-Encoding is absent --- .../Tests/Component/HttpFoundation/StreamedResponseTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Symfony/Tests/Component/HttpFoundation/StreamedResponseTest.php b/tests/Symfony/Tests/Component/HttpFoundation/StreamedResponseTest.php index 389e775f97a6d..e58e844eec44f 100644 --- a/tests/Symfony/Tests/Component/HttpFoundation/StreamedResponseTest.php +++ b/tests/Symfony/Tests/Component/HttpFoundation/StreamedResponseTest.php @@ -33,6 +33,7 @@ public function testPrepareWith11Protocol() $response->prepare($request); $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')); }