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

Fix error core JS proxy couldn't be decoded when gzipped #15056

Merged
merged 2 commits into from Nov 8, 2019
Merged

Conversation

tsteur
Copy link
Member

@tsteur tsteur commented Oct 24, 2019

refs matomo-org/matomo-for-wordpress#40

This happens when eg WordPress might be triggering a notice before we do the "readfile" in which case the notice will be mixed with the gzipped content in the response and therefore the browser cannot read the gzipped JS/CSS. You can easily reproduce this by eg replacing the ob_get_clean with an echo 'foobar';

Something I don't quite understand yet is why it works when echoing something after the _readfile. In theory we would need to exit right away.

refs matomo-org/matomo-for-wordpress#40

This happens when eg WordPress might be triggering a notice before we do the "readfile" in which case the notice will be mixed with the gzipped content in the response and therefore the browser cannot read the gzipped JS/CSS. You can easily reproduce this by eg replacing the `ob_get_clean` with an `echo 'foobar';`

Something I don't quite understand yet is why it works when echoing something after the `_readfile`. In theory we would need to exit right away.
@tsteur tsteur added not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org. Needs Review PRs that need a code review labels Oct 24, 2019
@tsteur tsteur added this to the 3.13.0 milestone Oct 24, 2019
@@ -170,6 +170,8 @@ public static function serverStaticFile($file, $contentType, $expireFarFutureDay
Common::sendHeader('Content-Encoding: ' . $encoding);
}

@ob_get_clean();
Copy link
Member

Choose a reason for hiding this comment

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

As the buffer content does not matter and is not used, guess a ob_end_clean() might be better

Copy link
Member Author

Choose a reason for hiding this comment

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

In WordPress the buffer may be used so didn't want to end them as wasn't sure if it could have any side effects. Shouldn't really make much of a difference? Although I suppose ob_end_clean would make sure it'll be printed I suppose? This is currently done in WordPress on shutdown by looping through all of them and then printing them basically. Eg ob_end_clean might call some callbacks that then will be executed and could break things when expecting some wrong output maybe not sure https://www.php.net/manual/en/function.ob-end-clean.php#42939

Copy link
Member

Choose a reason for hiding this comment

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

According to https://www.php.net/manual/en/function.ob-get-clean.php ob_get_clean also executes ob_end_clean. So guess it doesn't make much difference...

Copy link
Member Author

Choose a reason for hiding this comment

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

👍 didn't know. Changed it to ob_end_clean and also now iterating over multiple output bufferings

@diosmosis diosmosis merged commit a6e68de into 3.x-dev Nov 8, 2019
@diosmosis diosmosis deleted the gzipproxy branch November 8, 2019 03:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Review PRs that need a code review not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants