Skip to content

Commit d1601f2

Browse files
committed
Add support for configurable HTTP request factory for proxy clients
1 parent 83ed7e4 commit d1601f2

File tree

8 files changed

+46
-0
lines changed

8 files changed

+46
-0
lines changed

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

tests/Unit/DependencyInjection/ConfigurationTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public function testSupportsAllConfigFormats()
105105
'servers' => ['22.22.22.22'],
106106
'base_url' => '/test',
107107
'http_client' => 'acme.guzzle.varnish',
108+
'request_factory' => null,
108109
],
109110
],
110111
],
@@ -241,6 +242,7 @@ public function testSupportsNginx()
241242
'servers' => ['22.22.22.22'],
242243
'base_url' => '/test',
243244
'http_client' => 'acme.guzzle.nginx',
245+
'request_factory' => null,
244246
],
245247
],
246248
];
@@ -276,6 +278,7 @@ public function testSupportsSymfony()
276278
'servers' => ['22.22.22.22'],
277279
'base_url' => '/test',
278280
'http_client' => 'acme.guzzle.symfony',
281+
'request_factory' => null,
279282
],
280283
'use_kernel_dispatcher' => false,
281284
],
@@ -505,6 +508,7 @@ public function testSplitOptions()
505508
'base_url' => null,
506509
'http_client' => null,
507510
'servers' => ['1.1.1.1:80', '2.2.2.2:80'],
511+
'request_factory' => null,
508512
],
509513
'tags_header' => 'X-Cache-Tags',
510514
'tag_mode' => 'ban',
@@ -515,6 +519,7 @@ public function testSplitOptions()
515519
'base_url' => null,
516520
'http_client' => null,
517521
'servers' => ['1.1.1.1:81', '2.2.2.2:81'],
522+
'request_factory' => null,
518523
],
519524
],
520525
];
@@ -756,6 +761,7 @@ public function testUserContextLogoutHandler(string $configFile, $expected, $cac
756761
'servers' => ['localhost'],
757762
'base_url' => null,
758763
'http_client' => null,
764+
'request_factory' => null,
759765
];
760766
$expectedConfiguration['proxy_client'][$proxyClient]['purge_location'] = false;
761767
}
@@ -859,6 +865,7 @@ public function testSupportsServersFromJsonEnv(): void
859865
'servers_from_jsonenv' => '%env(json:VARNISH_SERVERS)%',
860866
'base_url' => '/test',
861867
'http_client' => 'acme.guzzle.nginx',
868+
'request_factory' => null,
862869
],
863870
'tag_mode' => 'ban',
864871
'tags_header' => 'X-Cache-Tags',

0 commit comments

Comments
 (0)