Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POST method should not throw exception on empty payload without content-type #2297

Open
wants to merge 2 commits into
base: 3.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions EventListener/BodyListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function onKernelRequest(RequestEvent $event): void

if (null === $format || !$this->decoderProvider->supports($format)) {
if ($this->throwExceptionOnUnsupportedContentType
&& $this->isNotAnEmptyDeleteRequestWithNoSetContentType($method, $content, $contentType)
&& $this->isNotAnEmptyPostOrDeleteRequestWithNoSetContentType($method, $content, $contentType)
) {
throw new UnsupportedMediaTypeHttpException("Request body format '$format' not supported");
}
Expand Down Expand Up @@ -109,9 +109,9 @@ public function onKernelRequest(RequestEvent $event): void
}
}

private function isNotAnEmptyDeleteRequestWithNoSetContentType(string $method, $content, ?string $contentType): bool
private function isNotAnEmptyPostOrDeleteRequestWithNoSetContentType(string $method, $content, ?string $contentType): bool
{
return false === ('DELETE' === $method && empty($content) && empty($contentType));
return false === (in_array($method, ['DELETE', 'POST'], true) && empty($content) && empty($contentType));
}

private function isDecodeable(Request $request): bool
Expand Down