headers->set('Cache-Control', 'no-cache, no-store, must-revalidate, private, max-age=0, s-maxage=0'); $response->headers->set('Pragma', 'no-cache'); $response->headers->set('Expires', 'Thu, 01 Jan 1970 00:00:00 GMT'); // Cloudflare-specific: Tell Cloudflare to bypass cache for this response // CDN-Cache-Control is respected by Cloudflare and other CDNs $response->headers->set('CDN-Cache-Control', 'no-store'); // Cloudflare also respects this header $response->headers->set('Cloudflare-CDN-Cache-Control', 'no-store'); // Add Vary header to ensure caches differentiate by user session $existingVary = $response->headers->get('Vary', ''); $varyHeaders = array_filter(array_map('trim', explode(',', $existingVary))); // Add Cookie to Vary header if not already present if (! in_array('Cookie', $varyHeaders, true)) { $varyHeaders[] = 'Cookie'; } // Add Authorization to Vary header for API requests if ($request->bearerToken() && ! in_array('Authorization', $varyHeaders, true)) { $varyHeaders[] = 'Authorization'; } $response->headers->set('Vary', implode(', ', $varyHeaders)); } return $response; } }