Skip to content

Commit

Permalink
Merge pull request #267 from buhta/master
Browse files Browse the repository at this point in the history
Allow json requests with empty body
  • Loading branch information
wolfy-j committed Jun 5, 2020
2 parents f4a3d8b + 1c6008b commit 9fd831d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Http/Middleware/JsonPayloadMiddleware.php
Expand Up @@ -44,9 +44,12 @@ public function __construct(JsonPayloadConfig $config)
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
if ($this->isJsonPayload($request)) {
$request = $request->withParsedBody(json_decode((string)$request->getBody(), true));
if (json_last_error() !== 0) {
throw new ClientException(400, 'invalid json payload');
$body = (string)$request->getBody();
if ($body !== '') {
$request = $request->withParsedBody(json_decode($body, true));
if (json_last_error() !== 0) {
throw new ClientException(400, 'invalid json payload');
}
}
}

Expand Down

0 comments on commit 9fd831d

Please sign in to comment.