diff --git a/src/JsonApi.php b/src/JsonApi.php index d9debae..e7cf939 100644 --- a/src/JsonApi.php +++ b/src/JsonApi.php @@ -110,11 +110,17 @@ final class JsonApi implements RequestHandlerInterface { $header = $request->getHeaderLine('Accept'); - if (empty($header) || $header === '*/*') { + if (empty($header)) { return; } - if ((new MediaTypes($header))->containsExactly(self::CONTENT_TYPE)) { + $mediaTypes = new MediaTypes($header); + + if ($mediaTypes->containsExactly('*/*')) { + return; + } + + if ($mediaTypes->containsExactly(self::CONTENT_TYPE)) { return; } diff --git a/tests/specification/ContentNegotiationTest.php b/tests/specification/ContentNegotiationTest.php index 655c344..3485f3e 100644 --- a/tests/specification/ContentNegotiationTest.php +++ b/tests/specification/ContentNegotiationTest.php @@ -48,7 +48,7 @@ class ContentNegotiationTest extends AbstractTestCase ); } - public function test_error_when_valid_request_content_type_has_parameters() + public function test_error_when_request_content_type_has_parameters() { $request = $this->buildRequest('PATCH', '/users/1') ->withHeader('Content-Type', 'application/vnd.api+json;profile="http://example.com/last-modified"'); @@ -58,7 +58,7 @@ class ContentNegotiationTest extends AbstractTestCase $this->api->handle($request); } - public function test_error_when_all_valid_accepts_have_parameters() + public function test_error_when_all_accepts_have_parameters() { $request = $this->buildRequest('GET', '/users/1') ->withHeader('Accept', 'application/vnd.api+json;profile="http://example.com/last-modified", application/vnd.api+json;profile="http://example.com/versioning"'); @@ -77,4 +77,14 @@ class ContentNegotiationTest extends AbstractTestCase $this->assertEquals(200, $response->getStatusCode()); } + + public function test_success_when_accepts_wildcard() + { + $response = $this->api->handle( + $this->buildRequest('GET', '/users/1') + ->withHeader('Accept', '*/*') + ); + + $this->assertEquals(200, $response->getStatusCode()); + } }