Allow wildcard Accepts
This commit is contained in:
parent
57ffa867c8
commit
ce085c32f3
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue