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: page cache saves Response data before running after filters #6282

Merged
merged 9 commits into from
Jul 30, 2022

Conversation

kenjis
Copy link
Member

@kenjis kenjis commented Jul 20, 2022

Description
Fixes #6281

The page cache saves Response data before running after filters.
So response headers added by after filters and response body changes by after filters will be lost.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@kenjis kenjis added the bug Verified issues on the current code behavior or pull requests that will fix them label Jul 20, 2022
@iRedds
Copy link
Collaborator

iRedds commented Jul 20, 2022

Since the issue affects the operation of the SecureHeaders filter, it seems to me that it would also be correct to return the Response in the SecureHeaders::after() method.

@kenjis
Copy link
Member Author

kenjis commented Jul 20, 2022

What do you mean?
What's the difference between to return the Response in the SecureHeaders::after() and not to return?

@iRedds
Copy link
Collaborator

iRedds commented Jul 20, 2022

@kenjis If we are targeting the implementation of PSR-15 in version 5, then it would be logical to prepare the codebase for the correct behavior. So that it doesn’t work out, as with legacy 3.x, when, with the transfer of the code base from 3.x to 4.x, the code started to work incorrectly or not as intended.

But yes, within the framework of the current concept of the framework, my proposal does not make sense.

@kenjis
Copy link
Member Author

kenjis commented Jul 20, 2022

@iRedds I got your point. But I think it is related not only SecureHeaders but also all after filters.
The after() method should always return ResponseInterface.
And if we change the API, at least we must go to 4.3 branch.

We can't do anything in this PR.

@kenjis kenjis added the breaking change Pull requests that may break existing functionalities label Jul 20, 2022
@kenjis kenjis force-pushed the fix-cachePage-secureheaders branch from e514e5c to 901860b Compare July 21, 2022 01:28
@kenjis
Copy link
Member Author

kenjis commented Jul 21, 2022

Added the upgrade guide.

@kenjis kenjis force-pushed the fix-cachePage-secureheaders branch from 901860b to 91f6f1c Compare July 21, 2022 01:33
Copy link
Member

@MGatner MGatner left a comment

Choose a reason for hiding this comment

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

A few typos then looks good! Thanks for adding the explicit docs.

// Cache it without the performance metrics replaced
// so that we can have live speed updates along the way.
// Must be run after filters to preserve the Response headers.
if (static::$cacheTTL > 0) {
Copy link
Member

Choose a reason for hiding this comment

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

Are you certain that 0 indicates "don't cache"? Sometimes it means "never expire".

Copy link
Member

Choose a reason for hiding this comment

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

Nevermind, I see this was just moved from below!

user_guide_src/source/installation/upgrade_422.rst Outdated Show resolved Hide resolved
user_guide_src/source/installation/upgrade_422.rst Outdated Show resolved Hide resolved
Copy link
Member

@MGatner MGatner left a comment

Choose a reason for hiding this comment

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

A few typos then looks good! Thanks for adding the explicit docs.

kenjis and others added 2 commits July 23, 2022 06:12
Co-authored-by: MGatner <mgatner@icloud.com>
Co-authored-by: MGatner <mgatner@icloud.com>
*/
public function run(?RouteCollectionInterface $routes = null, bool $returnResponse = false)
{
if ($this->context === null) {
throw new LogicException('Context must be set before run() is called. If you are upgrading from 4.1.x, you need to merge `public/index.php` and `spark` file from `vendor/codeigniter4/framework`.');
}

static::$cacheTTL = 0;
Copy link
Member

Choose a reason for hiding this comment

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

is it means that cacheTTL value is reset in every run?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes.

$cacheTTL will be set by a Controller.

@kenjis kenjis merged commit aba1ac1 into codeigniter4:develop Jul 30, 2022
@kenjis kenjis deleted the fix-cachePage-secureheaders branch July 30, 2022 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change Pull requests that may break existing functionalities bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: secureheaders does not work with cache
4 participants