diff --git a/src/HttpCache/SouinPurger.php b/src/HttpCache/SouinPurger.php index 4fc2ff73cc..8c85ea1275 100644 --- a/src/HttpCache/SouinPurger.php +++ b/src/HttpCache/SouinPurger.php @@ -13,6 +13,7 @@ namespace ApiPlatform\HttpCache; +use Symfony\Component\HttpFoundation\Request; use Symfony\Contracts\HttpClient\HttpClientInterface; /** @@ -29,8 +30,8 @@ class SouinPurger extends SurrogateKeysPurger /** * @param HttpClientInterface[] $clients */ - public function __construct(iterable $clients, int $maxHeaderLength = self::MAX_HEADER_SIZE_PER_BATCH) + public function __construct(iterable $clients, int $maxHeaderLength = self::MAX_HEADER_SIZE_PER_BATCH, string $method = Request::METHOD_PURGE) { - parent::__construct($clients, $maxHeaderLength, self::HEADER, self::SEPARATOR); + parent::__construct($clients, $maxHeaderLength, self::HEADER, self::SEPARATOR, $method); } } diff --git a/src/HttpCache/SurrogateKeysPurger.php b/src/HttpCache/SurrogateKeysPurger.php index 0890d5e4e0..8604061be2 100644 --- a/src/HttpCache/SurrogateKeysPurger.php +++ b/src/HttpCache/SurrogateKeysPurger.php @@ -31,7 +31,7 @@ class SurrogateKeysPurger implements PurgerInterface /** * @param HttpClientInterface[] $clients */ - public function __construct(protected readonly iterable $clients, protected readonly int $maxHeaderLength = self::MAX_HEADER_SIZE_PER_BATCH, protected readonly string $header = self::HEADER, protected readonly string $separator = self::SEPARATOR) + public function __construct(protected readonly iterable $clients, protected readonly int $maxHeaderLength = self::MAX_HEADER_SIZE_PER_BATCH, protected readonly string $header = self::HEADER, protected readonly string $separator = self::SEPARATOR, protected readonly string $method = Request::METHOD_PURGE) { } @@ -71,7 +71,7 @@ public function purge(array $iris): void foreach ($this->clients as $client) { $client->request( - Request::METHOD_PURGE, + $this->method, '', ['headers' => [$this->header => $chunk]] ); diff --git a/src/HttpCache/Tests/SouinPurgerTest.php b/src/HttpCache/Tests/SouinPurgerTest.php index 7bba11d827..7d4422cd94 100644 --- a/src/HttpCache/Tests/SouinPurgerTest.php +++ b/src/HttpCache/Tests/SouinPurgerTest.php @@ -150,4 +150,13 @@ public function testGetResponseHeaders(): void self::assertSame(['Surrogate-Key' => 'first-value/, second'], $purger->getResponseHeaders(['first-value/', 'second'])); self::assertSame(['Surrogate-Key' => 'C0mplex_Value/, The value with spaces'], $purger->getResponseHeaders(['C0mplex_Value/', 'The value with spaces'])); } + + public function testPurgeWithCustomHttpMethod(): void + { + $clientProphecy = $this->prophesize(HttpClientInterface::class); + $clientProphecy->request('DELETE', '', ['headers' => ['Surrogate-Key' => '/foo']])->shouldBeCalled(); + + $purger = new SouinPurger([$clientProphecy->reveal()], method: Request::METHOD_DELETE); + $purger->purge(['/foo']); + } }