]> BookStack Code Mirror - bookstack/blob - app/Http/Middleware/PreventResponseCaching.php
Updated translator & dependency attribution before release v25.05.1
[bookstack] / app / Http / Middleware / PreventResponseCaching.php
1 <?php
2
3 namespace BookStack\Http\Middleware;
4
5 use Closure;
6 use Symfony\Component\HttpFoundation\Response;
7
8 class PreventResponseCaching
9 {
10     /**
11      * Paths to ignore when preventing response caching.
12      */
13     protected array $ignoredPathPrefixes = [
14         'theme/',
15     ];
16
17     /**
18      * Handle an incoming request.
19      *
20      * @param \Illuminate\Http\Request $request
21      * @param \Closure                 $next
22      *
23      * @return mixed
24      */
25     public function handle($request, Closure $next)
26     {
27         /** @var Response $response */
28         $response = $next($request);
29
30         $path = $request->path();
31         foreach ($this->ignoredPathPrefixes as $ignoredPath) {
32             if (str_starts_with($path, $ignoredPath)) {
33                 return $response;
34             }
35         }
36
37         $response->headers->set('Cache-Control', 'no-cache, no-store, private');
38         $response->headers->set('Expires', 'Sun, 12 Jul 2015 19:01:00 GMT');
39
40         return $response;
41     }
42 }
Morty Proxy This is a proxified and sanitized view of the page, visit original site.