Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Changelog

* If a custom proxy client is configured on the cache manager, the `ProxyClient` class is an alias to that client, to support autowiring.
* Attribute configuration now also works on single action controllers with the `__invoke` method.
* New configuration option `proxy_client.*.http.request_factory` to support custom HTTP request factories for proxy clients.

3.1.2
-----
Expand Down Expand Up @@ -53,6 +54,11 @@ Changelog
2.x
===

2.18.0
------

* New configuration option `proxy_client.*.http.request_factory` to support custom HTTP request factories for proxy clients.

2.17.1
------

Expand Down
3 changes: 2 additions & 1 deletion Resources/doc/features/invalidation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ To refresh paths and routes, you can use ``refreshPath($path, $headers)`` and

If you want to add a header (such as ``Authorization``) to *all*
invalidation requests, you can use a
:ref:`custom HTTP client <custom HTTP client>` instead.
:ref:`custom HTTP client <custom HTTP client>` or
:ref:`custom HTTP request factory <custom HTTP request factory>` instead.

.. _invalidation configuration:

Expand Down
9 changes: 9 additions & 0 deletions Resources/doc/reference/configuration/proxy-client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,15 @@ example to send a basic authentication header with each request, you can
configure a service for the ``HttpClient`` and specify that in the
``http_client`` option of any of the cache proxy clients.

.. _custom HTTP request factory:

Custom HTTP Request Factory
---------------------------

The proxy client uses an implementation of ``Http\Message\RequestFactory`` to create HTTP requests.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is different for FOSHttpCache v3 (it changed to Psr\Http\Message\RequestFactoryInterface) but v3 of the bundle supports v2 and v3 of the lib. How do we properly document that?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point. i actually don't see value in keeping to support FOSHttpCache 2.x with the 3.x bundle. both have the same minimum PHP version, so there is no good argument to use different major versions.

i will adjust accordingly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, and we also added a psr-17 stream factory optional argument. for consistency we should support that as well.

Copy link
Contributor

@jdreesen jdreesen Jun 17, 2025

Choose a reason for hiding this comment

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

ah, and we also added a psr-17 stream factory optional argument. for consistency we should support that as well.

Should I create a PR for that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

FriendsOfSymfony/FOSHttpCache#595 for improving the phpdoc vor FOSHttpCache 3.x

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks. i already committed it in this branch :-D

If you need to customize the request creation, you can configure your custom service and
specify that in the ``request_factory`` option of any of the cache proxy clients.

Caching Proxy Configuration
---------------------------

Expand Down
4 changes: 4 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,10 @@ private function getHttpDispatcherNode(): ArrayNodeDefinition
->defaultNull()
->info('Httplug async client service name to use for sending the requests.')
->end()
->scalarNode('request_factory')
->defaultNull()
->info('Service name of factory for PSR-7 messages.')
->end()
->end()
;

Expand Down
30 changes: 30 additions & 0 deletions src/DependencyInjection/FOSHttpCacheExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,12 @@ private function loadVarnish(ContainerBuilder $container, XmlFileLoader $loader,
$container->setParameter('fos_http_cache.proxy_client.varnish.options', $options);

$loader->load('varnish.xml');

$requestFactory = isset($config['http']['request_factory'])
? new Reference($config['http']['request_factory'])
: null;
$container->getDefinition('fos_http_cache.proxy_client.varnish')
->replaceArgument(2, $requestFactory);
}

private function loadNginx(ContainerBuilder $container, XmlFileLoader $loader, array $config): void
Expand All @@ -436,6 +442,12 @@ private function loadNginx(ContainerBuilder $container, XmlFileLoader $loader, a
'purge_location' => $config['purge_location'],
]);
$loader->load('nginx.xml');

$requestFactory = isset($config['http']['request_factory'])
? new Reference($config['http']['request_factory'])
: null;
$container->getDefinition('fos_http_cache.proxy_client.nginx')
->replaceArgument(2, $requestFactory);
}

private function loadSymfony(ContainerBuilder $container, XmlFileLoader $loader, array $config): void
Expand All @@ -462,6 +474,12 @@ private function loadSymfony(ContainerBuilder $container, XmlFileLoader $loader,
$container->setParameter('fos_http_cache.proxy_client.symfony.options', $options);

$loader->load('symfony.xml');

$requestFactory = isset($config['http']['request_factory'])
? new Reference($config['http']['request_factory'])
: null;
$container->getDefinition('fos_http_cache.proxy_client.symfony')
->replaceArgument(2, $requestFactory);
}

private function loadCloudflare(ContainerBuilder $container, XmlFileLoader $loader, array $config): void
Expand All @@ -475,6 +493,12 @@ private function loadCloudflare(ContainerBuilder $container, XmlFileLoader $load
$container->setParameter('fos_http_cache.proxy_client.cloudflare.options', $options);

$loader->load('cloudflare.xml');

$requestFactory = isset($config['http']['request_factory'])
? new Reference($config['http']['request_factory'])
: null;
$container->getDefinition('fos_http_cache.proxy_client.cloudflare')
->replaceArgument(2, $requestFactory);
}

private function loadCloudfront(ContainerBuilder $container, XmlFileLoader $loader, array $config): void
Expand Down Expand Up @@ -511,6 +535,12 @@ private function loadFastly(ContainerBuilder $container, XmlFileLoader $loader,
$container->setParameter('fos_http_cache.proxy_client.fastly.options', $options);

$loader->load('fastly.xml');

$requestFactory = isset($config['http']['request_factory'])
? new Reference($config['http']['request_factory'])
: null;
$container->getDefinition('fos_http_cache.proxy_client.fastly')
->replaceArgument(2, $requestFactory);
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/cloudflare.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
lazy="true">
<argument type="service" id="fos_http_cache.proxy_client.cloudflare.http_dispatcher"/>
<argument>%fos_http_cache.proxy_client.cloudflare.options%</argument>
<argument /> <!-- request factory -->
</service>
</services>

Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/fastly.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
lazy="true">
<argument type="service" id="fos_http_cache.proxy_client.fastly.http_dispatcher"/>
<argument>%fos_http_cache.proxy_client.fastly.options%</argument>
<argument /> <!-- request factory -->
</service>
</services>

Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/nginx.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
public="true">
<argument type="service" id="fos_http_cache.proxy_client.nginx.http_dispatcher"/>
<argument>%fos_http_cache.proxy_client.nginx.options%</argument>
<argument /> <!-- request factory -->
</service>
</services>

Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/symfony.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
public="true">
<argument type="service" id="fos_http_cache.proxy_client.symfony.http_dispatcher"/>
<argument>%fos_http_cache.proxy_client.symfony.options%</argument>
<argument /> <!-- request factory -->
</service>
</services>

Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/varnish.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
public="true">
<argument type="service" id="fos_http_cache.proxy_client.varnish.http_dispatcher"/>
<argument>%fos_http_cache.proxy_client.varnish.options%</argument>
<argument /> <!-- request factory -->
Copy link
Contributor

Choose a reason for hiding this comment

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

We could use a new Symfony 5.1 feature here: https://symfony.com/blog/new-in-symfony-5-1-abstract-service-arguments

I don't know what your strategy with this this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah right, that is a thing now. but as null is a valid argument here, i would keep this as is.

</service>
</services>

Expand Down
8 changes: 8 additions & 0 deletions tests/Unit/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public function testSupportsAllConfigFormats(): void
'servers' => ['22.22.22.22'],
'base_url' => '/test',
'http_client' => 'acme.guzzle.varnish',
'request_factory' => null,
],
],
],
Expand Down Expand Up @@ -241,6 +242,7 @@ public function testSupportsNginx(): void
'servers' => ['22.22.22.22'],
'base_url' => '/test',
'http_client' => 'acme.guzzle.nginx',
'request_factory' => null,
],
],
];
Expand Down Expand Up @@ -276,6 +278,7 @@ public function testSupportsSymfony(): void
'servers' => ['22.22.22.22'],
'base_url' => '/test',
'http_client' => 'acme.guzzle.symfony',
'request_factory' => null,
],
'use_kernel_dispatcher' => false,
],
Expand Down Expand Up @@ -506,6 +509,7 @@ public function testSplitOptions(): void
'base_url' => null,
'http_client' => null,
'servers' => ['1.1.1.1:80', '2.2.2.2:80'],
'request_factory' => null,
],
'tags_header' => 'X-Cache-Tags',
'tag_mode' => 'ban',
Expand All @@ -516,6 +520,7 @@ public function testSplitOptions(): void
'base_url' => null,
'http_client' => null,
'servers' => ['1.1.1.1:81', '2.2.2.2:81'],
'request_factory' => null,
],
],
];
Expand Down Expand Up @@ -757,6 +762,7 @@ public function testUserContextLogoutHandler(string $configFile, $expected, $cac
'servers' => ['localhost'],
'base_url' => null,
'http_client' => null,
'request_factory' => null,
];
$expectedConfiguration['proxy_client'][$proxyClient]['purge_location'] = false;
}
Expand Down Expand Up @@ -796,6 +802,7 @@ public function testSupportsServersFromJsonEnv(): void
'servers_from_jsonenv' => '%env(json:VARNISH_SERVERS)%',
'base_url' => '/test',
'http_client' => 'acme.guzzle.nginx',
'request_factory' => null,
],
'tag_mode' => 'ban',
'tags_header' => 'X-Cache-Tags',
Expand Down Expand Up @@ -829,6 +836,7 @@ public function testConfigureExpressionLanguageService(): void
'servers_from_jsonenv' => '%env(json:VARNISH_SERVERS)%',
'base_url' => '/test',
'http_client' => 'acme.guzzle.nginx',
'request_factory' => null,
],
'tag_mode' => 'ban',
'tags_header' => 'X-Cache-Tags',
Expand Down
Loading