Skip to content
Open
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
9 changes: 6 additions & 3 deletions src/DependencyInjection/FOSHttpCacheExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -745,9 +745,12 @@ private function determineGenerateUrlType(array $config): int
}

$defaultClient = $this->getDefaultProxyClient($config['proxy_client']);
if ('noop' !== $defaultClient
&& array_key_exists('base_url', $config['proxy_client'][$defaultClient])) {
return UrlGeneratorInterface::ABSOLUTE_PATH;
if ('noop' !== $defaultClient) {
$clientConfig = $config['proxy_client'][$defaultClient];
$hasBaseUrl = !empty($clientConfig['base_url'] ?? null) || !empty($clientConfig['http']['base_url'] ?? null);
if ($hasBaseUrl) {
return UrlGeneratorInterface::ABSOLUTE_PATH;
}
}
if ('cloudfront' === $defaultClient) {
return UrlGeneratorInterface::ABSOLUTE_PATH;
Expand Down
33 changes: 33 additions & 0 deletions tests/Unit/DependencyInjection/FOSHttpCacheExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\Router;

class FOSHttpCacheExtensionTest extends TestCase
Expand All @@ -53,6 +54,38 @@ public function testConfigLoadVarnish(): void
$this->assertTrue($container->hasDefinition('fos_http_cache.event_listener.tag'));
}

public function testVarnishWithBaseUrlAutoResolvesAbsolutePath(): void
{
$container = $this->createContainer();
$this->extension->load([$this->getBaseConfig()], $container);

$this->assertSame(
UrlGeneratorInterface::ABSOLUTE_PATH,
$container->getParameter('fos_http_cache.cache_manager.generate_url_type'),
'Varnish with base_url must auto-resolve to ABSOLUTE_PATH so the Host header uses base_url, not the CMS request hostname.'
);
}

public function testVarnishWithoutBaseUrlAutoResolvesAbsoluteUrl(): void
{
$container = $this->createContainer();
$config = [
'proxy_client' => [
'varnish' => [
'http' => [
'servers' => ['127.0.0.1'],
],
],
],
];
$this->extension->load([$config], $container);

$this->assertSame(
UrlGeneratorInterface::ABSOLUTE_URL,
$container->getParameter('fos_http_cache.cache_manager.generate_url_type')
);
}

public function testConfigLoadVarnishCustomClient(): void
{
$container = $this->createContainer();
Expand Down
Loading