diff --git a/system/Filters/PageCache.php b/system/Filters/PageCache.php index 9fda34ba4e24..53740509072c 100644 --- a/system/Filters/PageCache.php +++ b/system/Filters/PageCache.php @@ -17,6 +17,7 @@ use CodeIgniter\HTTP\CLIRequest; use CodeIgniter\HTTP\DownloadResponse; use CodeIgniter\HTTP\IncomingRequest; +use CodeIgniter\HTTP\Method; use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; @@ -65,6 +66,10 @@ public function after(RequestInterface $request, ResponseInterface $response, $a { assert($request instanceof CLIRequest || $request instanceof IncomingRequest); + if ($this->isNotCacheableMethod($request)) { + return; + } + if ( ! $response instanceof DownloadResponse && ! $response instanceof RedirectResponse @@ -75,4 +80,19 @@ public function after(RequestInterface $request, ResponseInterface $response, $a $this->pageCache->make($request, $response); } } + + private function isNotCacheableMethod(RequestInterface $request): bool + { + return in_array( + $request->getMethod(), + [ + Method::CONNECT, + Method::DELETE, + Method::OPTIONS, + Method::PUT, + Method::TRACE, + ], + true + ); + } }