Skip to content

Commit

Permalink
Merge pull request #13161 from cakephp/issue-13156
Browse files Browse the repository at this point in the history
Remove charset on json content-type
  • Loading branch information
markstory committed Apr 25, 2019
2 parents 97ae5b3 + f996038 commit 96a8a2e
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 10 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
Expand Up @@ -167,7 +167,7 @@ public function testHandleExceptionPreserveRequest()
$this->assertNotSame($result, $response);
$this->assertEquals(404, $result->getStatusCode());
$this->assertContains('"message": "whoops"', '' . $result->getBody());
$this->assertEquals('application/json; charset=UTF-8', $result->getHeaderLine('Content-type'));
$this->assertEquals('application/json', $result->getHeaderLine('Content-type'));
}

/**
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
4 changes: 2 additions & 2 deletions tests/TestCase/TestSuite/IntegrationTestTraitTest.php
Expand Up @@ -331,7 +331,7 @@ public function testExceptionsInMiddlewareJsonView()
$this->_request['headers'] = [ "Accept" => "application/json" ];
$this->get('/json_response/api_get_data');
$this->assertResponseCode(403);
$this->assertHeader('Content-Type', 'application/json; charset=UTF-8');
$this->assertHeader('Content-Type', 'application/json');
$this->assertResponseContains('"message": "Sample Message"');
$this->assertResponseContains('"code": 403');
}
Expand Down Expand Up @@ -1137,7 +1137,7 @@ public function testAssertContentType()
public function testContentTypeInAction()
{
$this->get('/tests_apps/set_type');
$this->assertHeader('Content-Type', 'application/json; charset=UTF-8');
$this->assertHeader('Content-Type', 'application/json');
$this->assertContentType('json');
$this->assertContentType('application/json');
}
Expand Down

0 comments on commit 96a8a2e

Please sign in to comment.