StandardServer: a bit more validation for parsed json PSR-7 request (related to #202)

This commit is contained in:
Vladimir Razuvaev 2017-11-28 12:28:54 +07:00
parent 9d37f4c0d9
commit 0af2fe79f2

View File

@ -493,16 +493,21 @@ class Helper
);
}
// Try parsing ourselves if PSR-7 implementation doesn't parse JSON automatically
if (is_array($bodyParams) && empty($bodyParams)) {
$bodyParams = json_decode($request->getBody(), true);
if (json_last_error()) {
throw new RequestError("Could not parse JSON: " . json_last_error_msg());
}
}
if (!is_array($bodyParams)) {
throw new RequestError(
"GraphQL Server expects JSON object or array, but got " .
Utils::printSafeJson($bodyParams)
);
}
if (empty($bodyParams)) {
$bodyParams = json_decode($request->getBody(), true);
}
} else {
$bodyParams = $request->getParsedBody();