Skip to content

Commit

Permalink
Not sending a content-length for redirection status codes that are no…
Browse files Browse the repository at this point in the history
…t supposed to have any content
  • Loading branch information
lorenzo committed Oct 28, 2011
1 parent aabfad9 commit 9866882
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/Cake/Network/CakeResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,8 @@ public function send() {
$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) {
Expand Down
8 changes: 8 additions & 0 deletions lib/Cake/Test/Case/Network/CakeResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -416,5 +416,13 @@ public function testSendContentLength() {
$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();
}
}

0 comments on commit 9866882

Please sign in to comment.