Using the Static Caching half measures we've encountered an issue with response headers, applied via custom middleware or controller logic, being stripped out of a cached response.
Statamic\StaticCaching\Cachers\ApplicationCacher only seems to cache the response contents and ignores any other response object details, including headers. This can result in cached responses missing important headers which may have been defined anywhere in the request stack.
How to reproduce
Create a controller which returns a response with a text/plain header.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Statamic\Facades\Entry;
class AdsTxtController
{
public function __invoke(Request $request): Response
{
$entry = Entry::find(1);
return response($entry->content)->withHeaders([
'Content-Type' => 'text/plain',
]);
}
}
Bug description
Using the Static Caching half measures we've encountered an issue with response headers, applied via custom middleware or controller logic, being stripped out of a cached response.
Statamic\StaticCaching\Cachers\ApplicationCacher
only seems to cache the response contents and ignores any other response object details, including headers. This can result in cached responses missing important headers which may have been defined anywhere in the request stack.How to reproduce
Create a controller which returns a response with a
text/plain
header.Add a route with the statamic.web middleware
Make a request to the endpoint - observe the content-type is different from the request without the cache middleware. With middleware
Without middleware
Logs
No response
Environment
Installation
Existing Laravel app
Antlers Parser
None
Additional details
No response