| 
									
										
										
										
											2021-10-08 22:22:09 +08:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace BookStack\Http\Middleware; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | use Closure; | 
					
						
							|  |  |  | use Symfony\Component\HttpFoundation\Response; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 20:32:15 +08:00
										 |  |  | class PreventResponseCaching | 
					
						
							| 
									
										
										
										
											2021-10-08 22:22:09 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2025-01-13 22:30:53 +08:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Paths to ignore when preventing response caching. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     protected array $ignoredPathPrefixes = [ | 
					
						
							|  |  |  |         'theme/', | 
					
						
							|  |  |  |     ]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-08 22:22:09 +08:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Handle an incoming request. | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2021-10-09 05:23:17 +08:00
										 |  |  |      * @param \Illuminate\Http\Request $request | 
					
						
							|  |  |  |      * @param \Closure                 $next | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2021-10-08 22:22:09 +08:00
										 |  |  |      * @return mixed | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function handle($request, Closure $next) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         /** @var Response $response */ | 
					
						
							|  |  |  |         $response = $next($request); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-13 22:30:53 +08:00
										 |  |  |         $path = $request->path(); | 
					
						
							|  |  |  |         foreach ($this->ignoredPathPrefixes as $ignoredPath) { | 
					
						
							|  |  |  |             if (str_starts_with($path, $ignoredPath)) { | 
					
						
							|  |  |  |                 return $response; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 20:32:15 +08:00
										 |  |  |         $response->headers->set('Cache-Control', 'no-cache, no-store, private'); | 
					
						
							|  |  |  |         $response->headers->set('Expires', 'Sun, 12 Jul 2015 19:01:00 GMT'); | 
					
						
							| 
									
										
										
										
											2021-10-08 22:22:09 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $response; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |