From 98668825062bbdafc14a24fa7ff311549d6a3bd5 Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Thu, 27 Oct 2011 23:18:49 -0430 Subject: [PATCH] Not sending a content-length for redirection status codes that are not supposed to have any content --- lib/Cake/Network/CakeResponse.php | 4 ++-- lib/Cake/Test/Case/Network/CakeResponseTest.php | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Network/CakeResponse.php b/lib/Cake/Network/CakeResponse.php index e65b8899c..41cb0f412 100644 --- a/lib/Cake/Network/CakeResponse.php +++ b/lib/Cake/Network/CakeResponse.php @@ -351,8 +351,8 @@ class CakeResponse { $this->_sendHeader("{$this->_protocol} {$this->_status} {$codeMessage}"); $this->_sendHeader('Content-Type', "{$this->_contentType}; charset={$this->_charset}"); $shouldSetLength = empty($this->_headers['Content-Length']) && class_exists('Multibyte'); - $shouldSetLength = $shouldSetLength && !$this->outputCompressed(); - if ($shouldSetLength) { + $shouldSetLength = $shouldSetLength && !in_array($this->_status, range(301, 307)); + if ($shouldSetLength && !$this->outputCompressed()) { $this->_headers['Content-Length'] = mb_strlen($this->_body); } foreach ($this->_headers as $header => $value) { diff --git a/lib/Cake/Test/Case/Network/CakeResponseTest.php b/lib/Cake/Test/Case/Network/CakeResponseTest.php index 680081cfd..c118fd62e 100644 --- a/lib/Cake/Test/Case/Network/CakeResponseTest.php +++ b/lib/Cake/Test/Case/Network/CakeResponseTest.php @@ -416,5 +416,13 @@ class CakeResponseTest extends CakeTestCase { $response->expects($this->at(2)) ->method('_sendHeader')->with('Content-Length', 1); $response->send(); + + $response = $this->getMock('CakeResponse', array('_sendHeader', '_sendContent')); + $body = 'content'; + $response->statusCode(301); + $response->body($body); + $response->expects($this->once())->method('_sendContent')->with($body); + $response->expects($this->exactly(2))->method('_sendHeader'); + $response->send(); } }