Skip to content

Commit 39c21ea

Browse files
authored
Merge pull request #1699 from mickaelprevot/invalidation-verify-ssl
Added the verify_ssl option for the cache invalidation
2 parents e807580 + 742bb16 commit 39c21ea

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

src/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ private function registerHttpCache(ContainerBuilder $container, array $config, X
505505
$definitions = [];
506506
foreach ($config['http_cache']['invalidation']['varnish_urls'] as $key => $url) {
507507
$definition = new ChildDefinition('api_platform.http_cache.purger.varnish_client');
508-
$definition->addArgument(['base_uri' => $url]);
508+
$definition->addArgument(['base_uri' => $url] + $config['http_cache']['invalidation']['request_options']);
509509

510510
$definitions[] = $definition;
511511
}

src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,14 @@ public function getConfigTreeBuilder()
212212
->prototype('scalar')->end()
213213
->info('URLs of the Varnish servers to purge using cache tags when a resource is updated.')
214214
->end()
215+
->variableNode('request_options')
216+
->defaultValue([])
217+
->validate()
218+
->ifTrue(function ($v) { return false === is_array($v); })
219+
->thenInvalid('The request_options parameter must be an array.')
220+
->end()
221+
->info('To pass options to the client charged with the request.')
222+
->end()
215223
->end()
216224
->end()
217225
->end()

tests/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,22 @@ class ApiPlatformExtensionTest extends TestCase
7373
'http_cache' => ['invalidation' => [
7474
'enabled' => true,
7575
'varnish_urls' => ['test'],
76+
'request_options' => [
77+
'allow_redirects' => [
78+
'max' => 5,
79+
'protocols' => ['http', 'https'],
80+
'stric' => false,
81+
'referer' => false,
82+
'track_redirects' => false,
83+
],
84+
'http_errors' => true,
85+
'decode_content' => false,
86+
'verify' => false,
87+
'cookies' => true,
88+
'headers' => [
89+
'User-Agent' => 'none',
90+
],
91+
],
7692
]],
7793
]];
7894

@@ -344,6 +360,17 @@ public function testNotRegisterHttpCacheWhenEnabledWithNoVarnishServer()
344360
$this->extension->load($config, $containerBuilder);
345361
}
346362

363+
public function testRegisterHttpCacheWhenEnabledWithNoRequestOption()
364+
{
365+
$containerBuilderProphecy = $this->getBaseContainerBuilderProphecy();
366+
$containerBuilder = $containerBuilderProphecy->reveal();
367+
368+
$config = self::DEFAULT_CONFIG;
369+
unset($config['api_platform']['http_cache']['invalidation']['request_options']);
370+
371+
$this->extension->load($config, $containerBuilder);
372+
}
373+
347374
private function getPartialContainerBuilderProphecy($test = false)
348375
{
349376
$containerBuilderProphecy = $this->prophesize(ContainerBuilder::class);

tests/Bridge/Symfony/Bundle/DependencyInjection/ConfigurationTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,11 @@ public function testDefaultConfig()
126126
'paths' => [],
127127
],
128128
'http_cache' => [
129-
'invalidation' => ['enabled' => false, 'varnish_urls' => []],
129+
'invalidation' => [
130+
'enabled' => false,
131+
'varnish_urls' => [],
132+
'request_options' => [],
133+
],
130134
'etag' => true,
131135
'max_age' => null,
132136
'shared_max_age' => null,

0 commit comments

Comments
 (0)