Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always parse body if inputFormat is set #213

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 7 additions & 19 deletions src/frapi/library/Frapi/Controller/Main.php
Expand Up @@ -328,29 +328,14 @@ public function setParams(array $params)
{
// read the raw input to get the request body
$input = file_get_contents("php://input");
parse_str($input, $puts);

$inputFormat = $this->inputFormat;
if(empty($inputFormat)) {
$xmlJsonMatch = preg_grep('/\<|\{/i', array_keys($puts));
$inputFormat = $this->getFormat();
}

/**
* When doing parse_str("{json:string}") it creates an array like:
* array(
* "{json:string}" => ""
* )
*
* If args are also present along with the body, they are in the array
* before the body.
*
* Checks if the last argument is an empty string, this + inputForm is
* indicative of the body needing parsing.
*/
if (end($puts) == '' && !empty($inputFormat) || !empty($xmlJsonMatch)) {
if (!empty($inputFormat)) {
/* attempt to parse the input */
reset($puts);
$requestBody = Frapi_Input_RequestBodyParser::parse(
$inputFormat,
$input
Expand All @@ -369,9 +354,12 @@ public function setParams(array $params)

$params = array_merge($params, $requestBody);
}
} else if (!empty($puts)) {
foreach ($puts as $put => $val) {
$params[$put] = $val;
} else {
parse_str($input, $puts);
if (!empty($puts)) {
foreach ($puts as $put => $val) {
$params[$put] = $val;
}
}
}

Expand Down