Added Content-Type: application/json body support for PSR-7 ServerRequest

This commit is contained in:
Matias Griese 2019-03-21 12:01:05 +02:00
parent a25d18bca7
commit 90c708db2b
2 changed files with 13 additions and 0 deletions

View File

@ -1,3 +1,9 @@
# v1.6.0-rc.5
## mm/dd/2019
1. [](#improved)
* Added `Content-Type: application/json` body support for PSR-7 `ServerRequest`
# v1.6.0-rc.4
## 03/20/2019

View File

@ -23,6 +23,13 @@ class RequestProcessor extends ProcessorBase
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface
{
$this->startTimer();
$header = $request->getHeaderLine('Content-Type');
$type = trim(strstr($header, ';', true) ?: $header);
if ($type === 'application/json') {
$request = $request->withParsedBody(json_decode($request->getBody()->getContents(), true));
}
$request = $request
->withAttribute('grav', $this->container)
->withAttribute('time', $_SERVER['REQUEST_TIME_FLOAT'] ?? GRAV_REQUEST_TIME)