mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 17:16:18 +00:00
Merge pull request #283 from ichikaway/returnByteOfContentLength
return byte length in HTTP Content-Length
This commit is contained in:
commit
f2b47e3d3f
2 changed files with 7 additions and 6 deletions
|
@ -17,8 +17,6 @@
|
|||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
App::uses('Multibyte', 'I18n');
|
||||
|
||||
/**
|
||||
* CakeResponse is responsible for managing the response text, status and headers of a HTTP response.
|
||||
*
|
||||
|
@ -350,10 +348,13 @@ class CakeResponse {
|
|||
$codeMessage = $this->_statusCodes[$this->_status];
|
||||
$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 && !in_array($this->_status, range(301, 307));
|
||||
$shouldSetLength = empty($this->_headers['Content-Length']) && !in_array($this->_status, range(301, 307));
|
||||
if ($shouldSetLength && !$this->outputCompressed()) {
|
||||
$this->_headers['Content-Length'] = mb_strlen($this->_body);
|
||||
if (ini_get('mbstring.func_overload') & 2 && function_exists('mb_strlen')) {
|
||||
$this->_headers['Content-Length'] = mb_strlen($this->_body, '8bit');
|
||||
} else {
|
||||
$this->_headers['Content-Length'] = strlen($this->_body);
|
||||
}
|
||||
}
|
||||
foreach ($this->_headers as $header => $value) {
|
||||
$this->_sendHeader($header, $value);
|
||||
|
|
|
@ -396,7 +396,7 @@ class CakeResponseTest extends CakeTestCase {
|
|||
$response->expects($this->at(1))
|
||||
->method('_sendHeader')->with('Content-Type', 'text/html; charset=UTF-8');
|
||||
$response->expects($this->at(2))
|
||||
->method('_sendHeader')->with('Content-Length', mb_strlen($body));
|
||||
->method('_sendHeader')->with('Content-Length', 116);
|
||||
$response->send();
|
||||
|
||||
$response = $this->getMock('CakeResponse', array('_sendHeader', '_sendContent', 'outputCompressed'));
|
||||
|
|
Loading…
Add table
Reference in a new issue