5
5
use Closure ;
6
6
use Illuminate \Support \Carbon ;
7
7
use Illuminate \Support \Str ;
8
+ use Leantime \Core \Services \AuthService ;
8
9
use Symfony \Component \HttpFoundation \BinaryFileResponse ;
9
10
use Symfony \Component \HttpFoundation \StreamedResponse ;
10
11
11
12
class SetCacheHeaders
12
13
{
14
+ private AuthService $ authService ;
15
+
16
+ public function __construct (AuthService $ authService )
17
+ {
18
+ $ this ->authService = $ authService ;
19
+ }
20
+
13
21
/**
14
22
* Specify the options for the middleware.
15
23
*
@@ -39,7 +47,6 @@ public static function using($options)
39
47
* Add cache related HTTP headers.
40
48
*
41
49
* @param \Illuminate\Http\Request $request
42
- * @param \Closure $next
43
50
* @param string|array $options
44
51
* @return \Symfony\Component\HttpFoundation\Response
45
52
*
@@ -49,6 +56,15 @@ public function handle($request, Closure $next, $options = [])
49
56
{
50
57
$ response = $ next ($ request );
51
58
59
+ // For authenticated routes, set strict no-cache headers
60
+ if ($ this ->authService ->loggedIn ()) {
61
+ $ response ->headers ->set ('Cache-Control ' , 'no-store, no-cache, must-revalidate, max-age=0 ' );
62
+ $ response ->headers ->set ('Pragma ' , 'no-cache ' );
63
+ $ response ->headers ->set ('Expires ' , 'Sat, 01 Jan 2000 00:00:00 GMT ' );
64
+
65
+ return $ response ;
66
+ }
67
+
52
68
if (! $ request ->isMethodCacheable () || (! $ response ->getContent () && ! $ response instanceof BinaryFileResponse && ! $ response instanceof StreamedResponse)) {
53
69
return $ response ;
54
70
}
0 commit comments