Skip to content

Commit 3a9a3fa

Browse files
committed
Support headers like: application/json; charset=utf-8
1 parent 15df10a commit 3a9a3fa

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/JsonDecodeMiddleware.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function post(
4949
}
5050

5151
if (!isset($options[self::class]) &&
52-
$response->getHeaderLine('Content-Type') !== 'application/json') {
52+
strpos($response->getHeaderLine('Content-Type'), 'application/json') !== 0) {
5353
return resolve($response);
5454
}
5555

tests/JsonDecodeMiddlewareTest.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,21 @@
1515

1616
class JsonDecodeMiddlewareTest extends TestCase
1717
{
18-
public function testPost()
18+
public function provideValidJsonContentTypes()
19+
{
20+
yield ['application/json'];
21+
yield ['application/json; charset=utf-8'];
22+
}
23+
24+
/**
25+
* @dataProvider provideValidJsonContentTypes
26+
*/
27+
public function testPost(string $contentType)
1928
{
2029
$loop = Factory::create();
2130
$service = new JsonDecodeService($loop);
2231
$middleware = new JsonDecodeMiddleware($service);
23-
$response = new Response(200, ['Content-Type' => 'application/json'], '[]');
32+
$response = new Response(200, ['Content-Type' => $contentType], '[]');
2433

2534
$body = await(
2635
$middleware->post($response, 'abc'),

0 commit comments

Comments
 (0)