diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e8dba08c..fa46189a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/system/src/Grav/Common/Processors/RequestProcessor.php b/system/src/Grav/Common/Processors/RequestProcessor.php index f59b78aa3..8cb876a39 100644 --- a/system/src/Grav/Common/Processors/RequestProcessor.php +++ b/system/src/Grav/Common/Processors/RequestProcessor.php @@ -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)