zendframework / zend-diactoros

PSR-7 HTTP Message implementation
BSD 3-Clause "New" or "Revised" License
1.56k stars 152 forks source link

JSON requests not parsed when using ServerRequestFactory #278

Closed RinkAttendant6 closed 6 years ago

RinkAttendant6 commented 6 years ago

The body of JSON requests is not being populated into the parsedBody property of the ServerRequest object when using \Zend\Diactoros\ServerRequestFactory::fromGlobals. In fact, nothing appears to be parsed at all. Please see the following example:

Request (only relevant parts included):

Content-Type: application/json

{"foo": "bar"}

Code:

$request = \Zend\Diactoros\ServerRequestFactory::fromGlobals($_SERVER, $_GET, $_POST, $_COOKIE, $_FILES);
print_r($request->getParsedBody());

Result:

Array
(
)

Expected result:

Array
(
    [foo] => bar
)
Xerkus commented 6 years ago

Works as intended. zend-diactoros does not perform content negotiation. It is a responsibility of application, for example in zend-expressive: https://docs.zendframework.com/zend-expressive/features/helpers/body-parse/