Skip to content

Commit 40a2451

Browse files
authored
Add support for configurable HTTP request factory for proxy clients (#646)
1 parent 83ed7e4 commit 40a2451

File tree

11 files changed

+62
-1
lines changed

11 files changed

+62
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ Changelog
44
2.x
55
===
66

7+
2.18.0
8+
------
9+
10+
* New configuration option `proxy_client.*.http.request_factory` to support custom HTTP request factories for proxy clients.
11+
712
2.17.1
813
------
914

Resources/doc/features/invalidation.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ To refresh paths and routes, you can use ``refreshPath($path, $headers)`` and
6666

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

7172
.. _invalidation configuration:
7273

Resources/doc/reference/configuration/proxy-client.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,15 @@ example to send a basic authentication header with each request, you can
402402
configure a service for the ``HttpClient`` and specify that in the
403403
``http_client`` option of any of the cache proxy clients.
404404

405+
.. _custom HTTP request factory:
406+
407+
Custom HTTP Request Factory
408+
---------------------------
409+
410+
The proxy client uses an implementation of ``Http\Message\RequestFactory`` to create HTTP requests.
411+
If you need to customize the request creation, you can configure your custom service and
412+
specify that in the ``request_factory`` option of any of the cache proxy clients.
413+
405414
Caching Proxy Configuration
406415
---------------------------
407416

src/DependencyInjection/Configuration.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,10 @@ private function getHttpDispatcherNode()
641641
->defaultNull()
642642
->info('Httplug async client service name to use for sending the requests.')
643643
->end()
644+
->scalarNode('request_factory')
645+
->defaultNull()
646+
->info('Service name of factory for PSR-7 messages.')
647+
->end()
644648
->end()
645649
;
646650

src/DependencyInjection/FOSHttpCacheExtension.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,12 @@ private function loadVarnish(ContainerBuilder $container, XmlFileLoader $loader,
430430
$container->setParameter('fos_http_cache.proxy_client.varnish.options', $options);
431431

432432
$loader->load('varnish.xml');
433+
434+
$requestFactory = isset($config['http']['request_factory'])
435+
? new Reference($config['http']['request_factory'])
436+
: null;
437+
$container->getDefinition('fos_http_cache.proxy_client.varnish')
438+
->replaceArgument(2, $requestFactory);
433439
}
434440

435441
private function loadNginx(ContainerBuilder $container, XmlFileLoader $loader, array $config)
@@ -439,6 +445,12 @@ private function loadNginx(ContainerBuilder $container, XmlFileLoader $loader, a
439445
'purge_location' => $config['purge_location'],
440446
]);
441447
$loader->load('nginx.xml');
448+
449+
$requestFactory = isset($config['http']['request_factory'])
450+
? new Reference($config['http']['request_factory'])
451+
: null;
452+
$container->getDefinition('fos_http_cache.proxy_client.nginx')
453+
->replaceArgument(2, $requestFactory);
442454
}
443455

444456
private function loadSymfony(ContainerBuilder $container, XmlFileLoader $loader, array $config)
@@ -465,6 +477,12 @@ private function loadSymfony(ContainerBuilder $container, XmlFileLoader $loader,
465477
$container->setParameter('fos_http_cache.proxy_client.symfony.options', $options);
466478

467479
$loader->load('symfony.xml');
480+
481+
$requestFactory = isset($config['http']['request_factory'])
482+
? new Reference($config['http']['request_factory'])
483+
: null;
484+
$container->getDefinition('fos_http_cache.proxy_client.symfony')
485+
->replaceArgument(2, $requestFactory);
468486
}
469487

470488
private function loadCloudflare(ContainerBuilder $container, XmlFileLoader $loader, array $config)
@@ -478,6 +496,12 @@ private function loadCloudflare(ContainerBuilder $container, XmlFileLoader $load
478496
$container->setParameter('fos_http_cache.proxy_client.cloudflare.options', $options);
479497

480498
$loader->load('cloudflare.xml');
499+
500+
$requestFactory = isset($config['http']['request_factory'])
501+
? new Reference($config['http']['request_factory'])
502+
: null;
503+
$container->getDefinition('fos_http_cache.proxy_client.cloudflare')
504+
->replaceArgument(2, $requestFactory);
481505
}
482506

483507
private function loadCloudfront(ContainerBuilder $container, XmlFileLoader $loader, array $config)
@@ -514,6 +538,12 @@ private function loadFastly(ContainerBuilder $container, XmlFileLoader $loader,
514538
$container->setParameter('fos_http_cache.proxy_client.fastly.options', $options);
515539

516540
$loader->load('fastly.xml');
541+
542+
$requestFactory = isset($config['http']['request_factory'])
543+
? new Reference($config['http']['request_factory'])
544+
: null;
545+
$container->getDefinition('fos_http_cache.proxy_client.fastly')
546+
->replaceArgument(2, $requestFactory);
517547
}
518548

519549
/**

src/Resources/config/cloudflare.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
public="true">
1111
<argument type="service" id="fos_http_cache.proxy_client.cloudflare.http_dispatcher"/>
1212
<argument>%fos_http_cache.proxy_client.cloudflare.options%</argument>
13+
<argument /> <!-- request factory -->
1314
</service>
1415
</services>
1516

src/Resources/config/fastly.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
public="false">
1111
<argument type="service" id="fos_http_cache.proxy_client.fastly.http_dispatcher"/>
1212
<argument>%fos_http_cache.proxy_client.fastly.options%</argument>
13+
<argument /> <!-- request factory -->
1314
</service>
1415
</services>
1516

src/Resources/config/nginx.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
public="true">
1111
<argument type="service" id="fos_http_cache.proxy_client.nginx.http_dispatcher"/>
1212
<argument>%fos_http_cache.proxy_client.nginx.options%</argument>
13+
<argument /> <!-- request factory -->
1314
</service>
1415
</services>
1516

src/Resources/config/symfony.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
public="true">
1111
<argument type="service" id="fos_http_cache.proxy_client.symfony.http_dispatcher"/>
1212
<argument>%fos_http_cache.proxy_client.symfony.options%</argument>
13+
<argument /> <!-- request factory -->
1314
</service>
1415
</services>
1516

src/Resources/config/varnish.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
public="true">
1111
<argument type="service" id="fos_http_cache.proxy_client.varnish.http_dispatcher"/>
1212
<argument>%fos_http_cache.proxy_client.varnish.options%</argument>
13+
<argument /> <!-- request factory -->
1314
</service>
1415
</services>
1516

0 commit comments

Comments
 (0)