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

GitHub Issue #177: make reading from php:https://input configurable #181

Merged
merged 12 commits into from
Jun 13, 2017

Conversation

ArturMoczulski
Copy link
Contributor

In response to feedback from #177 I decided to make reading the raw request body from php:https://input disabled by default and configurable through include_raw_request_body.

Unfortunately, I don't see any way to overcome PHP < 5.6 limitation of single read from php:https://input so I combined making it configurable and also saving the content of the stream for later use in $_SERVER['php:https://input']. This is not perfect, but I don't think we can do anything more for < 5.6 users due to PHP limitations.


protected function setIncludeRawRequestBody($config)
{
$fromConfig = $this->tryGet($config, 'include_raW_request_body');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/include_raW_request_body/include_raw_request_body/

If you still want to read the request body for your PUT requests Rollbar SDK saves
the content of php:https://input in $_SERVER['php:https://input']

Default: `false`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this something that most people assume should be there though? I feel like the default should be what we have been doing so far and allow people using < 5.6 to deal with the problem. But I am not sure, it is a shitty situation that I don't see a better solution for.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This alters the default behavior of PHP in what I would call an unexpected place. Because of this I would opt for keeping this disabled by default.

$this->requestBody = file_get_contents("php:https://input");
$_SERVER['php:https://input'] = $this->requestBody;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Saving request body into $_SERVER make sense to keep only for old PHP versions due to performance reason. And even withing old PHP versions it's a huge hack, IMO, to build the logic of own application based on some workaround behavior of vendor logging library. I would recommend to just remove this line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rokob For the same reasons I opt in for include_raw_request_body to be disabled by default.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we did

if (version_compare(PHP_VERSION, '5.6.0') < 0) {
    $_SERVER['php:https://input'] = $this->requestBody;
}

At least then we only do this hack when we need it.

@coryvirok coryvirok added the Type: Bug Fix a component so that its behavior aligns with its documentation. label Jun 7, 2017
@see http:https://php.net/manual/pl/wrappers.php.php#refsect2-wrappers.php-unknown-unknown-descriptiop
If you still want to read the request body for your PUT requests Rollbar SDK saves
the content of php:https://input in $_SERVER['php:https://input']

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's mention the default being false for this

$this->requestBody = file_get_contents("php:https://input");
$_SERVER['php:https://input'] = $this->requestBody;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do something like to only do this when absolutely necessary

if (version_compare(PHP_VERSION, '5.6.0') < 0) {
    $_SERVER['php:https://input'] = $this->requestBody;
}

src/Defaults.php Outdated
@@ -99,6 +99,11 @@ public function localVarsDump($localVarsDump = null)
return $localVarsDump !== null ? $localVarsDump : $this->defaultLocalVarsDump;
}

public function rawRequestBody($rawRequestBody = null)
{
return $rawRequestBody ? $rawRequestBody : $this->defaultRawRequestBody;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be testing for $rawRequestBody !== null

));
$output = $dataBuilder->makeData(Level::fromName('error'), "testing", array());
$requestBody = $output->getRequest()->getBody();

$this->assertEquals($streamInput, $requestBody);
$this->assertEquals($streamInput, $_SERVER['php:https://input']);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only do this check on less than 5.6

@rokob
Copy link
Contributor

rokob commented Jun 12, 2017

Other than the comments this looks good

@rokob
Copy link
Contributor

rokob commented Jun 13, 2017

This LGTM but there is still an issue with the tests taking too long, I'm going to merge this and deal with the test timeouts elsewhere.

@rokob rokob merged commit 704e7b6 into rollbar:master Jun 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Fix a component so that its behavior aligns with its documentation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants