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
23 changes: 12 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,30 @@
],
"require": {
"php": " >=8.3",
"friendsofsymfony/http-cache": "^2.9",
"friendsofsymfony/http-cache-bundle": "^2.8",
"friendsofsymfony/http-cache": "^3.1",
"ibexa/fos-http-cache-bundle": "^3.0",
"ibexa/core": "~5.0.x-dev",
"ibexa/rest": "~5.0.x-dev",
"php-http/curl-client": "^2.1",
"psr/http-client": "^1.0",
"symfony/config": "^6.4",
"symfony/dependency-injection": "^6.4",
"symfony/event-dispatcher": "^6.4",
"symfony/http-foundation": "^6.4",
"symfony/http-kernel": "^6.4",
"symfony/routing": "^6.4",
"symfony/yaml": "^6.4",
"symfony/config": "^7.2",
"symfony/dependency-injection": "^7.2",
"symfony/event-dispatcher": "^7.2",
"symfony/http-foundation": "^7.2",
"symfony/http-kernel": "^7.2",
"symfony/routing": "^7.2",
"symfony/yaml": "^7.2",
"toflar/psr6-symfony-http-cache-store": "^4.2"
},
"require-dev": {
"guzzlehttp/psr7": "^2.7",
"ibexa/code-style": "~2.0.0",
"ibexa/doctrine-schema": "~5.0.x-dev",
"ibexa/rector": "~5.0.x-dev",
"matthiasnoback/symfony-dependency-injection-test": "^4.3",
"matthiasnoback/symfony-dependency-injection-test": "^5.0",
"phpspec/phpspec": "^7.1",
"phpunit/phpunit": "^9.6",
"symfony/phpunit-bridge": "^6.4"
"symfony/phpunit-bridge": "^7.2"
},
"autoload": {
"psr-4": {
Expand Down
12 changes: 6 additions & 6 deletions spec/EventSubscriber/RestKernelViewSubscriberSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function it_writes_tags_on_section(
$request->isMethodCacheable()->willReturn(true);
$attributes->get('is_rest_request')->willReturn(true);

$tagHandler->addTags(['s5'])->shouldBeCalled();
$tagHandler->addTags(['s5'])->shouldBeCalled()->willReturn($tagHandler);

$event = new ViewEvent(
$kernel->getWrappedObject(),
Expand Down Expand Up @@ -142,7 +142,7 @@ public function it_writes_tags_on_content_type_defined(
$request->isMethodCacheable()->willReturn(true);
$attributes->get('is_rest_request')->willReturn(true);

$tagHandler->addTags(['t4'])->shouldBeCalled();
$tagHandler->addTags(['t4'])->shouldBeCalled()->willReturn($tagHandler);

$event = new ViewEvent(
$kernel->getWrappedObject(),
Expand Down Expand Up @@ -197,7 +197,7 @@ public function it_writes_tags_on_rest_content_type_defined(
$request->isMethodCacheable()->willReturn(true);
$attributes->get('is_rest_request')->willReturn(true);

$tagHandler->addTags(['t4'])->shouldBeCalled();
$tagHandler->addTags(['t4'])->shouldBeCalled()->willReturn($tagHandler);

$event = new ViewEvent(
$kernel->getWrappedObject(),
Expand Down Expand Up @@ -258,7 +258,7 @@ public function it_writes_tags_on_rest_content_type_group_ref_defined(
$request->isMethodCacheable()->willReturn(true);
$attributes->get('is_rest_request')->willReturn(true);

$tagHandler->addTags(['t4', 'tg2'])->shouldBeCalled();
$tagHandler->addTags(['t4', 'tg2'])->shouldBeCalled()->willReturn($tagHandler);

$event = new ViewEvent(
$kernel->getWrappedObject(),
Expand Down Expand Up @@ -287,7 +287,7 @@ public function it_writes_tags_on_rest_content_type_group_list(
$request->isMethodCacheable()->willReturn(true);
$attributes->get('is_rest_request')->willReturn(true);

$tagHandler->addTags(['tg2'])->shouldBeCalled();
$tagHandler->addTags(['tg2'])->shouldBeCalled()->willReturn($tagHandler);

$event = new ViewEvent(
$kernel->getWrappedObject(),
Expand Down Expand Up @@ -318,7 +318,7 @@ public function it_writes_tags_on_rest_version_list(
$request->isMethodCacheable()->willReturn(true);
$attributes->get('is_rest_request')->willReturn(true);

$tagHandler->addTags(['c33', 'cv33'])->shouldBeCalled();
$tagHandler->addTags(['c33', 'cv33'])->shouldBeCalled()->willReturn($tagHandler);

$event = new ViewEvent(
$kernel->getWrappedObject(),
Expand Down
4 changes: 2 additions & 2 deletions spec/EventSubscriber/UserContextSubscriberSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function it_tags_response_with_no_prefix(
$response->isCacheable()->willReturn(true);
$responseHeaders->get(Argument::exact('Content-Type'))->willReturn('application/vnd.fos.user-context-hash');
$response->getTtl()->willReturn(100);
$responseHeaders->set(Argument::exact('xkey'), Argument::exact('ez-user-context-hash'))->willReturn(null);
$responseHeaders->set(Argument::exact('xkey'), Argument::exact('ez-user-context-hash'));

$prefixService->getRepositoryPrefix()->willReturn('');

Expand All @@ -137,7 +137,7 @@ public function it_tags_response_with_a_prefix(
$response->getTtl()->willReturn(100);

$prefixService->getRepositoryPrefix()->willReturn('1');
$responseHeaders->set(Argument::exact('xkey'), Argument::exact('1ez-user-context-hash'))->willReturn(null);
$responseHeaders->set(Argument::exact('xkey'), Argument::exact('1ez-user-context-hash'));

$event = new ResponseEvent(
$kernel->getWrappedObject(),
Expand Down
10 changes: 6 additions & 4 deletions spec/EventSubscriber/XLocationIdResponseSubscriberSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function it_rewrite_header_with_location_info(
])
);

$tagHandler->addTags([
$tags = [
'l123',
'pl2',
'p1',
Expand All @@ -81,7 +81,9 @@ public function it_rewrite_header_with_location_info(
'c101',
'ct3',
'l120',
])->shouldBecalled();
];

$tagHandler->addTags($tags)->shouldBecalled()->willReturn($tagHandler);
$responseHeaders->remove('X-Location-Id')->shouldBecalled();

$event = new ResponseEvent(
Expand Down Expand Up @@ -109,7 +111,7 @@ public function it_rewrite_header_on_not_found_location(

$repository->sudo(new AnyValueToken())->willThrow(new NotFoundException('id', 123));

$tagHandler->addTags(['l123', 'p123'])->shouldBecalled();
$tagHandler->addTags(['l123', 'p123'])->shouldBecalled()->willReturn($tagHandler);
$responseHeaders->remove('X-Location-Id')->shouldBecalled();

$event = new ResponseEvent(
Expand Down Expand Up @@ -137,7 +139,7 @@ public function it_rewrite_header_also_in_unofficial_plural_form_and_merges_exis

$repository->sudo(new AnyValueToken())->willThrow(new NotFoundException('id', 123));

$tagHandler->addTags(['l123', 'p123', 'l34', 'p34'])->shouldBeCalled();
$tagHandler->addTags(['l123', 'p123', 'l34', 'p34'])->shouldBeCalled()->willReturn($tagHandler);
$responseHeaders->remove('X-Location-Id')->shouldBeCalled();

$event = new ResponseEvent(
Expand Down
40 changes: 28 additions & 12 deletions spec/ProxyClient/VarnishSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
namespace spec\Ibexa\HttpCache\ProxyClient;

use FOS\HttpCache\ProxyClient\Dispatcher;
use Http\Message\RequestFactory;
use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\RequestInterface;

class VarnishSpec extends ObjectBehavior
Expand All @@ -24,7 +24,7 @@ class VarnishSpec extends ObjectBehavior
public function let(
ConfigResolverInterface $configResolver,
Dispatcher $httpDispatcher,
RequestFactory $messageFactory,
RequestFactoryInterface $messageFactory,
RequestInterface $request
): void {
$messageFactory->createRequest(
Expand All @@ -34,12 +34,18 @@ public function let(
Argument::any()
)->willReturn($request);

$request->withHeader(
Argument::any(),
Argument::any()
)->willReturn($request);

$this->beConstructedWith($configResolver, $httpDispatcher, [], $messageFactory);
}

public function it_should_purge_with_additional_token_header_when_configuration_key_with_token_is_not_null(
ConfigResolverInterface $configResolver,
RequestFactory $messageFactory
RequestFactoryInterface $messageFactory,
RequestInterface $request
): void {
$configResolver->hasParameter('http_cache.varnish_invalidate_token')->willReturn(true);
$configResolver->getParameter('http_cache.varnish_invalidate_token')->willReturn('__TOKEN__');
Expand All @@ -48,27 +54,31 @@ public function it_should_purge_with_additional_token_header_when_configuration_

$this->requestShouldHaveBeenCreatedWithHeaders(
array_merge(self::REQUEST_HEADERS, ['X-Invalidate-Token' => '__TOKEN__']),
$messageFactory
$messageFactory,
$request
);
}

public function it_should_purge_without_additional_token_header_when_configuration_key_with_token_do_not_exist_in_configuration(
ConfigResolverInterface $configResolver,
RequestFactory $messageFactory
RequestFactoryInterface $messageFactory,
RequestInterface $request
): void {
$configResolver->hasParameter('http_cache.varnish_invalidate_token')->willReturn(false);

$this->purge(self::URI, self::REQUEST_HEADERS);

$this->requestShouldHaveBeenCreatedWithHeaders(
self::REQUEST_HEADERS,
$messageFactory
$messageFactory,
$request
);
}

public function it_should_purge_without_additional_token_header_when_configuration_key_with_token_exists_but_is_null(
ConfigResolverInterface $configResolver,
RequestFactory $messageFactory
RequestFactoryInterface $messageFactory,
RequestInterface $request
): void {
$configResolver->hasParameter('http_cache.varnish_invalidate_token')->willReturn(true);
$configResolver->getParameter('http_cache.varnish_invalidate_token')->willReturn(null);
Expand All @@ -77,17 +87,23 @@ public function it_should_purge_without_additional_token_header_when_configurati

$this->requestShouldHaveBeenCreatedWithHeaders(
self::REQUEST_HEADERS,
$messageFactory
$messageFactory,
$request
);
}

private function requestShouldHaveBeenCreatedWithHeaders(array $headers, RequestFactory $messageFactory): void
{
private function requestShouldHaveBeenCreatedWithHeaders(
array $headers,
RequestFactoryInterface $messageFactory,
RequestInterface $request
): void {
$messageFactory->createRequest(
'PURGE',
self::URI,
$headers,
Argument::any()
)->shouldHaveBeenCalled();

foreach ($headers as $name => $value) {
$request->withHeader($name, $value)->shouldHaveBeenCalled();
}
}
}
3 changes: 3 additions & 0 deletions spec/ResponseTagger/Value/ContentInfoTaggerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@
use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo;
use Ibexa\HttpCache\ResponseTagger\Value\ContentInfoTagger;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

class ContentInfoTaggerSpec extends ObjectBehavior
{
public function let(ResponseTagger $tagHandler): void
{
$this->beConstructedWith($tagHandler);

$tagHandler->addTags(Argument::any())->willReturn($tagHandler);
}

public function it_is_initializable(): void
Expand Down
2 changes: 2 additions & 0 deletions spec/ResponseTagger/Value/LocationTaggerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class LocationTaggerSpec extends ObjectBehavior
public function let(ResponseTagger $tagHandler): void
{
$this->beConstructedWith($tagHandler);

$tagHandler->addTags(Argument::any())->willReturn($tagHandler);
}

public function it_is_initializable(): void
Expand Down
2 changes: 2 additions & 0 deletions src/bundle/IbexaHttpCacheBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public function getContainerExtension(): ?ExtensionInterface
if ($this->extension) {
return $this->extension;
}

return null;
}

public function registerConfigParser(ContainerBuilder $container): void
Expand Down
4 changes: 0 additions & 4 deletions src/bundle/Resources/config/prepend/fos_http_cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,3 @@ user_context:
hash_cache_ttl: 600
# NOTE: These are also defined/used in AppCache, in Varnish VCL, and Fastly VCL
session_name_prefix: IBX_SESSION_ID

tags:
annotations:
enabled: false
2 changes: 1 addition & 1 deletion src/lib/Handler/TagHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function __construct(
$this->addTags(['ez-all']);
}

public function tagSymfonyResponse(Response $response, $replace = false)
public function tagSymfonyResponse(Response $response, bool $replace = false): static
{
$tags = [];
if (!$replace && $response->headers->has($this->getTagsHeaderName())) {
Expand Down
16 changes: 11 additions & 5 deletions src/lib/ProxyClient/Varnish.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
use FOS\HttpCache\ProxyClient\Invalidation\RefreshCapable;
use FOS\HttpCache\ProxyClient\Invalidation\TagCapable;
use FOS\HttpCache\ProxyClient\Varnish as FosVarnish;
use Http\Message\RequestFactory;
use Ibexa\Bundle\HttpCache\Controller\InvalidateTokenController;
use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface;
use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\UriInterface;

final class Varnish extends FosVarnish implements BanCapable, PurgeCapable, RefreshCapable, TagCapable
{
Expand All @@ -26,7 +27,7 @@ public function __construct(
ConfigResolverInterface $configResolver,
Dispatcher $httpDispatcher,
array $options = [],
?RequestFactory $messageFactory = null
?RequestFactoryInterface $messageFactory = null
) {
parent::__construct($httpDispatcher, $options, $messageFactory);
$this->configResolver = $configResolver;
Expand All @@ -51,8 +52,13 @@ private function getInvalidateToken(): ?string
return null;
}

protected function queueRequest($method, $url, array $headers, $validateHost = true, $body = null): void
{
parent::queueRequest($method, $url, $this->fetchAndMergeAuthHeaders($headers), $body);
protected function queueRequest(
string $method,
UriInterface|string $url,
array $headers,
bool $validateHost = true,
$body = null
): void {
parent::queueRequest($method, $url, $this->fetchAndMergeAuthHeaders($headers), body: $body);
}
}
Loading