mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Not appending the charset information for content types that are not text/* in CakeResponse
This commit is contained in:
parent
4d19d536f6
commit
f32c703e7e
2 changed files with 40 additions and 16 deletions
|
@ -348,15 +348,32 @@ class CakeResponse {
|
|||
|
||||
$codeMessage = $this->_statusCodes[$this->_status];
|
||||
$this->_sendHeader("{$this->_protocol} {$this->_status} {$codeMessage}");
|
||||
$this->_sendHeader('Content-Type', "{$this->_contentType}; charset={$this->_charset}");
|
||||
$this->_setContent();
|
||||
$this->_setContentLength();
|
||||
$this->_setContentType();
|
||||
foreach ($this->_headers as $header => $value) {
|
||||
$this->_sendHeader($header, $value);
|
||||
}
|
||||
$this->_sendContent($this->_body);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the Content-Type header based on the configured contentType and charset
|
||||
* the charset will only be set in the header if the response is of type text/*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _setContentType() {
|
||||
if (in_array($this->_status, array(304, 204))) {
|
||||
return;
|
||||
}
|
||||
if (strpos($this->_contentType, 'text/') === 0) {
|
||||
$this->header('Content-Type', "{$this->_contentType}; charset={$this->_charset}");
|
||||
} else {
|
||||
$this->header('Content-Type', "{$this->_contentType}");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the response body to an empty text if the status code is 204 or 304
|
||||
*
|
||||
|
|
|
@ -182,11 +182,13 @@ class CakeResponseTest extends CakeTestCase {
|
|||
$response->expects($this->at(0))
|
||||
->method('_sendHeader')->with('HTTP/1.1 200 OK');
|
||||
$response->expects($this->at(1))
|
||||
->method('_sendHeader')->with('Content-Type', 'text/html; charset=UTF-8');
|
||||
$response->expects($this->at(2))
|
||||
->method('_sendHeader')->with('Content-Language', 'es');
|
||||
$response->expects($this->at(3))
|
||||
$response->expects($this->at(2))
|
||||
->method('_sendHeader')->with('WWW-Authenticate', 'Negotiate');
|
||||
$response->expects($this->at(3))
|
||||
->method('_sendHeader')->with('Content-Length', 17);
|
||||
$response->expects($this->at(4))
|
||||
->method('_sendHeader')->with('Content-Type', 'text/html; charset=UTF-8');
|
||||
$response->send();
|
||||
}
|
||||
|
||||
|
@ -202,7 +204,9 @@ class CakeResponseTest extends CakeTestCase {
|
|||
$response->expects($this->at(0))
|
||||
->method('_sendHeader')->with('HTTP/1.1 200 OK');
|
||||
$response->expects($this->at(1))
|
||||
->method('_sendHeader')->with('Content-Type', 'audio/mpeg; charset=UTF-8');
|
||||
->method('_sendHeader')->with('Content-Length', 17);
|
||||
$response->expects($this->at(2))
|
||||
->method('_sendHeader')->with('Content-Type', 'audio/mpeg');
|
||||
$response->send();
|
||||
}
|
||||
|
||||
|
@ -218,7 +222,9 @@ class CakeResponseTest extends CakeTestCase {
|
|||
$response->expects($this->at(0))
|
||||
->method('_sendHeader')->with('HTTP/1.1 200 OK');
|
||||
$response->expects($this->at(1))
|
||||
->method('_sendHeader')->with('Content-Type', 'audio/mpeg; charset=UTF-8');
|
||||
->method('_sendHeader')->with('Content-Length', 17);
|
||||
$response->expects($this->at(2))
|
||||
->method('_sendHeader')->with('Content-Type', 'audio/mpeg');
|
||||
$response->send();
|
||||
}
|
||||
|
||||
|
@ -232,9 +238,9 @@ class CakeResponseTest extends CakeTestCase {
|
|||
$response->expects($this->at(0))
|
||||
->method('_sendHeader')->with('HTTP/1.1 302 Found');
|
||||
$response->expects($this->at(1))
|
||||
->method('_sendHeader')->with('Content-Type', 'text/html; charset=UTF-8');
|
||||
$response->expects($this->at(2))
|
||||
->method('_sendHeader')->with('Location', 'http://www.example.com');
|
||||
$response->expects($this->at(2))
|
||||
->method('_sendHeader')->with('Content-Type', 'text/html; charset=UTF-8');
|
||||
$response->send();
|
||||
}
|
||||
|
||||
|
@ -439,9 +445,9 @@ class CakeResponseTest extends CakeTestCase {
|
|||
$response->expects($this->once())->method('_sendContent')->with('the response body');
|
||||
$response->expects($this->at(0))
|
||||
->method('_sendHeader')->with('HTTP/1.1 200 OK');
|
||||
$response->expects($this->at(1))
|
||||
->method('_sendHeader')->with('Content-Type', 'text/html; charset=UTF-8');
|
||||
$response->expects($this->at(2))
|
||||
->method('_sendHeader')->with('Content-Type', 'text/html; charset=UTF-8');
|
||||
$response->expects($this->at(1))
|
||||
->method('_sendHeader')->with('Content-Length', strlen('the response body'));
|
||||
$response->send();
|
||||
|
||||
|
@ -451,9 +457,9 @@ class CakeResponseTest extends CakeTestCase {
|
|||
$response->expects($this->once())->method('_sendContent')->with($body);
|
||||
$response->expects($this->at(0))
|
||||
->method('_sendHeader')->with('HTTP/1.1 200 OK');
|
||||
$response->expects($this->at(1))
|
||||
->method('_sendHeader')->with('Content-Type', 'text/html; charset=UTF-8');
|
||||
$response->expects($this->at(2))
|
||||
->method('_sendHeader')->with('Content-Type', 'text/html; charset=UTF-8');
|
||||
$response->expects($this->at(1))
|
||||
->method('_sendHeader')->with('Content-Length', 116);
|
||||
$response->send();
|
||||
|
||||
|
@ -471,7 +477,7 @@ class CakeResponseTest extends CakeTestCase {
|
|||
$response->header('Content-Length', 1);
|
||||
$response->expects($this->never())->method('outputCompressed');
|
||||
$response->expects($this->once())->method('_sendContent')->with($body);
|
||||
$response->expects($this->at(2))
|
||||
$response->expects($this->at(1))
|
||||
->method('_sendHeader')->with('Content-Length', 1);
|
||||
$response->send();
|
||||
|
||||
|
@ -494,9 +500,9 @@ class CakeResponseTest extends CakeTestCase {
|
|||
$response->expects($this->at(0))
|
||||
->method('_sendHeader')->with('HTTP/1.1 200 OK');
|
||||
$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', strlen($goofyOutput) + 116);
|
||||
$response->expects($this->at(2))
|
||||
->method('_sendHeader')->with('Content-Type', 'text/html; charset=UTF-8');
|
||||
$response->send();
|
||||
ob_end_clean();
|
||||
}
|
||||
|
@ -524,7 +530,7 @@ class CakeResponseTest extends CakeTestCase {
|
|||
$response = $this->getMock('CakeResponse', array('_sendHeader', '_sendContent'));
|
||||
$response->length(100);
|
||||
$this->assertEquals(100, $response->length());
|
||||
$response->expects($this->at(2))
|
||||
$response->expects($this->at(1))
|
||||
->method('_sendHeader')->with('Content-Length', 100);
|
||||
$response->send();
|
||||
|
||||
|
@ -548,6 +554,7 @@ class CakeResponseTest extends CakeTestCase {
|
|||
$response->expects($this->once())
|
||||
->method('_sendContent')->with('');
|
||||
$response->send();
|
||||
$this->assertFalse(array_key_exists('Content-Type', $response->header()));
|
||||
|
||||
$response = $this->getMock('CakeResponse', array('_sendHeader', '_sendContent'));
|
||||
$response->body('This is a body');
|
||||
|
|
Loading…
Add table
Reference in a new issue