Skip to content

Commit

Permalink
Also accept the wildcard accept header for application/json
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeroen van den Nieuwenhuisen committed Jul 23, 2020
1 parent dbd9087 commit 75e66d6
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/Controller/CRUDController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1563,10 +1563,8 @@ private function setFormTheme(FormView $formView, ?array $theme = null): void

private function handleXmlHttpRequestErrorResponse(Request $request, FormInterface $form): ?JsonResponse
{
if (!\in_array('application/json', $request->getAcceptableContentTypes(), true)) {
@trigger_error('In next major version response will return 406 NOT ACCEPTABLE without `Accept: application/json`', E_USER_DEPRECATED);

return null;
if (0 === \count(array_intersect(['application/json', '*/*'], $request->getAcceptableContentTypes()))) {
return $this->renderJson([], Response::HTTP_NOT_ACCEPTABLE);
}

$errors = [];
Expand All @@ -1585,7 +1583,7 @@ private function handleXmlHttpRequestErrorResponse(Request $request, FormInterfa
*/
private function handleXmlHttpRequestSuccessResponse(Request $request, $object): JsonResponse
{
if (!\in_array('application/json', $request->getAcceptableContentTypes(), true)) {
if (0 === \count(array_intersect(['application/json', '*/*'], $request->getAcceptableContentTypes()))) {
@trigger_error('In next major version response will return 406 NOT ACCEPTABLE without `Accept: application/json`', E_USER_DEPRECATED);
}

Expand Down

0 comments on commit 75e66d6

Please sign in to comment.