Skip to content

Commit

Permalink
Remove charset on json content-type
Browse files Browse the repository at this point in the history
Don't emit a charset parameter on the json content type. Chrome has
started emitting warnings when this parameter is present as it isn't
compliant with the spec.

Fixes #13156
  • Loading branch information
markstory committed Apr 24, 2019
1 parent 266f1c9 commit e1fa054
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Http/Response.php
Expand Up @@ -581,7 +581,7 @@ protected function _setContentType()
return;
}
$whitelist = [
'application/javascript', 'application/json', 'application/xml', 'application/rss+xml'
'application/javascript', 'application/xml', 'application/rss+xml'
];

$charset = false;
Expand Down
3 changes: 1 addition & 2 deletions tests/TestCase/Http/ResponseTest.php
Expand Up @@ -315,7 +315,7 @@ public function testWithTypeAlias()
);
$this->assertSame('application/pdf', $new->getHeaderLine('Content-Type'));
$this->assertSame(
'application/json; charset=UTF-8',
'application/json',
$new->withType('json')->getHeaderLine('Content-Type')
);
}
Expand Down Expand Up @@ -463,7 +463,6 @@ public static function charsetTypeProvider()
return [
['mp3', 'audio/mpeg'],
['js', 'application/javascript; charset=UTF-8'],
['json', 'application/json; charset=UTF-8'],
['xml', 'application/xml; charset=UTF-8'],
['txt', 'text/plain; charset=UTF-8'],
];
Expand Down
4 changes: 0 additions & 4 deletions tests/TestCase/Http/ResponseTransformerTest.php
Expand Up @@ -301,10 +301,6 @@ public function testToPsrContentTypeCharsetIsTypeSpecific()
$cake->type('application/octet-stream');
$result = ResponseTransformer::toPsr($cake);
$this->assertSame('application/octet-stream', $result->getHeaderLine('Content-Type'));

$cake->type('application/json');
$result = ResponseTransformer::toPsr($cake);
$this->assertSame('application/json; charset=utf-8', $result->getHeaderLine('Content-Type'));
}

/**
Expand Down

0 comments on commit e1fa054

Please sign in to comment.