Skip to content

Commit

Permalink
Merge pull request #965 from frederikweber/patch-1
Browse files Browse the repository at this point in the history
Send charset in Content-Type when Content is JSON.
  • Loading branch information
markstory committed Nov 20, 2012
2 parents 4611c98 + 58df515 commit 04d4abf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions lib/Cake/Network/CakeResponse.php
Expand Up @@ -411,6 +411,8 @@ protected function _setContentType() {
}
if (strpos($this->_contentType, 'text/') === 0) {
$this->header('Content-Type', "{$this->_contentType}; charset={$this->_charset}");
} elseif ($this->_contentType === 'application/json') {
$this->header('Content-Type', "{$this->_contentType}; charset=UTF-8");
} else {
$this->header('Content-Type', "{$this->_contentType}");
}
Expand Down
10 changes: 5 additions & 5 deletions lib/Cake/Test/Case/Network/CakeResponseTest.php
Expand Up @@ -199,7 +199,7 @@ public function testSend() {
* Tests the send method and changing the content type
*
*/
public function testSendChangingContentYype() {
public function testSendChangingContentType() {
$response = $this->getMock('CakeResponse', array('_sendHeader', '_sendContent', '_setCookies'));
$response->type('mp3');
$response->body('the response body');
Expand All @@ -215,12 +215,12 @@ public function testSendChangingContentYype() {
}

/**
* Tests the send method and changing the content type
* Tests the send method and changing the content type to JSON
*
*/
public function testSendChangingContentType() {
public function testSendChangingContentTypeJSON() {
$response = $this->getMock('CakeResponse', array('_sendHeader', '_sendContent', '_setCookies'));
$response->type('mp3');
$response->type('json');
$response->body('the response body');
$response->expects($this->once())->method('_sendContent')->with('the response body');
$response->expects($this->at(0))->method('_setCookies');
Expand All @@ -229,7 +229,7 @@ public function testSendChangingContentType() {
$response->expects($this->at(2))
->method('_sendHeader')->with('Content-Length', 17);
$response->expects($this->at(3))
->method('_sendHeader')->with('Content-Type', 'audio/mpeg');
->method('_sendHeader')->with('Content-Type', 'application/json; charset=UTF-8');
$response->send();
}

Expand Down

0 comments on commit 04d4abf

Please sign in to comment.