JsonPayloadMiddleware should not try to decode body for GET requests
Currenly, GET requests with Content-Type: application/json will throw exception because JsonPayloadMiddleware tries to decode its empty body.
I think, middleware should fall back to empty arrays in such cases.
Correction: it fails for any kinds of requests with empty body.
Can you provide me the snapshot (runtime/snaphots) info? Or the details about the specific error.
[Spiral\Http\Exception\ClientException]
invalid json payloadin ~/project/vendor/spiral/framework/src/Http/Middleware/JsonPayloadMiddleware.php:35
Exception Trace:
Spiral\Http\Middleware\JsonPayloadMiddleware->process() at ~/project/vendor/spiral/framework/src/Http/Middleware/JsonPayloadMiddleware.php:35
Spiral\Http\Middleware\JsonPayloadMiddleware->process() at ~/project/vendor/spiral/http/src/Pipeline.php:82
Spiral\Http\Pipeline->handle() at ~/project/vendor/spiral/cookies/src/Middleware/CookiesMiddleware.php:59
Spiral\Cookies\Middleware\CookiesMiddleware->process() at ~/project/vendor/spiral/http/src/Pipeline.php:82
Spiral\Http\Pipeline->handle() at ~/project/vendor/spiral/http/src/Http.php:100
Spiral\Http\Http->handle() at ~/project/vendor/spiral/framework/src/Http/RrDispacher.php:80
Spiral\Http\RrDispacher->serve() at ~/project/vendor/spiral/core/src/ContainerScope.php:50
Spiral\Core\ContainerScope::runScope() at ~/project/vendor/spiral/core/src/Container.php:272
Spiral\Core\Container->runScope() at ~/project/vendor/spiral/boot/src/AbstractKernel.php:103
Spiral\Boot\AbstractKernel->serve() at ~/project/app.php:13
Technically, the 400 client error is expected when the payload is not valid. I need to think if easing validation is good approach.
Yes, I thought of that, too. But from practical standpoint, it would be an odd request to tell API consumers not to include Content-Type: application/json if they're not sending any data.
OK, I'll check if we can add it to the next release.
Fixed https://github.com/spiral/framework/pull/267