Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,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 @@ -402,6 +402,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.
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 @@ -641,6 +641,10 @@ private function getHttpDispatcherNode()
->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 @@ -430,6 +430,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)
Expand All @@ -439,6 +445,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)
Expand All @@ -465,6 +477,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)
Expand All @@ -478,6 +496,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)
Expand Down Expand Up @@ -514,6 +538,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 @@ -10,6 +10,7 @@
public="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 @@ -10,6 +10,7 @@
public="false">
<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 -->
</service>
</services>

Expand Down
7 changes: 7 additions & 0 deletions tests/Unit/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public function testSupportsAllConfigFormats()
'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()
'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()
'servers' => ['22.22.22.22'],
'base_url' => '/test',
'http_client' => 'acme.guzzle.symfony',
'request_factory' => null,
],
'use_kernel_dispatcher' => false,
],
Expand Down Expand Up @@ -505,6 +508,7 @@ public function testSplitOptions()
'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 @@ -515,6 +519,7 @@ public function testSplitOptions()
'base_url' => null,
'http_client' => null,
'servers' => ['1.1.1.1:81', '2.2.2.2:81'],
'request_factory' => null,
],
],
];
Expand Down Expand Up @@ -756,6 +761,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 @@ -859,6 +865,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
Loading