Skip to content

Commit

Permalink
fix(status codes cache): cache GET and HEAD methods only
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaucau committed Nov 23, 2024
1 parent a61086c commit 61532c8
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Middleware/StatusCodesCacheMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
use ACPL\FlarumLSCache\LSCacheHeader;
use Flarum\Http\RequestUtil;
use Flarum\Settings\SettingsRepositoryInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\{ResponseInterface, ServerRequestInterface};
use Psr\Http\Server\{MiddlewareInterface, RequestHandlerInterface};

class StatusCodesCacheMiddleware implements MiddlewareInterface
Expand All @@ -18,7 +17,8 @@ public function __construct(protected SettingsRepositoryInterface $settings)
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$response = $handler->handle($request);
if ($response->hasHeader(LSCacheHeader::CACHE_CONTROL)) {

if (! in_array($request->getMethod(), ['GET', 'HEAD']) || $response->hasHeader(LSCacheHeader::CACHE_CONTROL)) {
return $response;
}

Expand Down

0 comments on commit 61532c8

Please sign in to comment.