-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Description
Steps to reproduce the issue:
- Have a Symfony controller action that return this kind of response:
return new JsonResponse(['key' => $request->get('key')]);- then request this action like that:
# We don't set any Accept nor Content-Type header
curl -d '{"key": "value"} http://domain.tld/path Describe the results you received:
HTTP/1.1 200 OK
{"key": null}Describe the results you expected:
HTTP/1.1 406 Not AcceptableNote: Here we consider that we implement HTTP content negociation the right way so the client must provide a Content-Type header.
From where to start
The actual part of JsonBodyListener incrimined code is:
Other source(s) to watch for inspiration
FOSRestBundle FormatListener.php#L58-L75:
$format = $request->getRequestFormat(null);
if (null === $format) {
$accept = $this->formatNegotiator->getBest('');
if (null !== $accept && 0.0 < $accept->getQuality()) {
$format = $request->getFormat($accept->getValue());
if (null !== $format) {
$request->attributes->set('media_type', $accept->getValue());
}
}
}
if (null === $format) {
if ($event->getRequestType() === HttpKernelInterface::MASTER_REQUEST) {
throw new NotAcceptableHttpException('No matching accepted Response format could be determined');
}
return;
}Metadata
Metadata
Assignees
Labels
No labels