Skip to content

#643: Fix cache control expression Symfony DI configuration #644

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

Merged
merged 4 commits into from
May 12, 2025

Conversation

alongosz
Copy link
Contributor

This PR fixes #643.

As described in #643, there are 2 issues with the current Extension configuration, when defined as follows:

fos_http_cache:
    cache_control:
        rules:
            - match:
                  host: ^login.example.com$
                  match_response: 'response.isFresh()'
                  expression_language: 'app.expression_language'
              headers:
                  cache_control: {public: false}
  1. When using match_response option, we get the following Container compile-time error:
    Service "fos_http_cache.cache_control.expression.e4ac4270c49eeac61019bc369235175a": Cannot replace arguments for class "FOS\HttpCacheBundle\Http\ResponseMatcher\ExpressionResponseMatcher" if none have been configured yet.
    
  2. When using match_response_expression_service, we get an error that such option doesn't exist for the Extension. Seems expression_language should be used (as the Extension Configuration would suggest).

In both cases fixed replaceArgument to be setArgument. The former way worked in Symfony 5, but doesn't work in Symfony 6+.

The 1st issue occurs only at compile-time, therefore existing Extension tests configuring match_response wouldn't surface the issue as the definition structure is correct. Seems Symfony now processes those differently at compile time.
I added testContainerCompilesWithCacheControlExpressionConfig which compiles the container and performs no other assertions. We can see the mentioned error on the current state of the 3.x branch when running that test.

There's no coverage for 2nd argument, so I added testConfigLoadCacheControlExpressionWithOverriddenExpressionLanguage test.

Side note: Alternatively, adding the above options to ./tests/Functional/Fixtures/app/config/config.yml config, would also uncover the bug when running any KernelTestCase test as those actually compile the container as well.

Copy link
Contributor

@dbu dbu left a comment

Choose a reason for hiding this comment

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

awesome, thanks a lot! i will update the changelog and tag a release

@dbu dbu merged commit 9e62f28 into FriendsOfSymfony:3.x May 12, 2025
12 checks passed
@dbu
Copy link
Contributor

dbu commented May 12, 2025

https://github.com/FriendsOfSymfony/FOSHttpCacheBundle/releases/tag/3.1.2

@alongosz alongosz deleted the fix-cache-control-expr-di-config branch May 12, 2025 14:52
@alongosz
Copy link
Contributor Author

Thanks a lot @dbu 🙇 🎉

@dbu
Copy link
Contributor

dbu commented May 12, 2025

thank you for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to configure match_response for cache_control match rules for Symfony 7
3 participants