How to override Cache-Control header? #43460
Replies: 3 comments 4 replies
-
You can create a new middleware and then apply it inside <?php
// app/Http/Middleware/CacheControlMiddleware.php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
class CacheControlMiddleware
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
*/
public function handle(Request $request, Closure $next)
{
$response = $next($request);
$response->headers->set('Cache-Control', 'no-store');
return $response;
}
} |
Beta Was this translation helpful? Give feedback.
-
I think the right way here is to use built-in middleware - |
Beta Was this translation helpful? Give feedback.
-
Hi everyone, any solution to this? We're encountering an issue where Laravel (via Symfony HTTP Foundation) appends private or public to the Cache-Control headers, even when we explicitly set them. While we are able to override the default Cache-Control values, the appended directive (private or public) remains and cannot be removed. Here’s what we’ve tried so far:
Any guidance or solutions to prevent Symfony from appending private or public would be greatly appreciated! |
Beta Was this translation helpful? Give feedback.
-
Hi all,
Laravel application returns
Cache-Control: no-cache, private;
header by default.How I can override this and return just
no-store
?Best regards,
Sergey
Beta Was this translation helpful? Give feedback.
All reactions