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
5 changes: 3 additions & 2 deletions src/HttpCache/SouinPurger.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace ApiPlatform\HttpCache;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Contracts\HttpClient\HttpClientInterface;

/**
Expand All @@ -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);
}
}
4 changes: 2 additions & 2 deletions src/HttpCache/SurrogateKeysPurger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}

Expand Down Expand Up @@ -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]]
);
Expand Down
9 changes: 9 additions & 0 deletions src/HttpCache/Tests/SouinPurgerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
}
Loading