I have to return a specific cache-control header (Cache-Control: public, max-stale=13910400) but when run this, I get this: 
Cache-control has been duplicated, but I only need custom values.
$newResponse = $response->withHeader('Cache-Control', 'public, max-stale=13910400')->withJson($appInfo);
return $newResponse;
I tried this but it doesn't work (just for testing):
$newResponse = $response->withoutHeader('Cache-Control')->withHeader('Cache-Control', 'public, max-stale=13910400')->withJson($appInfo);
return $newResponse;
How can I set the header correctly?
Thank you
I suspect that you might have a middleware problem.
Your code above does produce the correct output.
$app->get('/test', function ($req, $res, $args) {
header_remove("Cache-Control"); //Edit <--
$newResponse = $res->withHeader('Cache-Control', 'public, max-stale=13910400')->withJson(["message" => "Test"]);
return $newResponse;
});
CURL Output
C:\Users\Glenn>curl -X GET -v http://localhost/vms2/public/test
HTTP/1.1 200 OK
Date: Tue, 13 Sep 2016 19:04:42 GMT * Server Apache/2.4.10 (Win32) OpenSSL/1.0.1i PHP/5.6.3 is not blacklisted
Server: Apache/2.4.10 (Win32) OpenSSL/1.0.1i PHP/5.6.3
X-Powered-By: PHP/5.6.3
Set-Cookie: VMS2=2qf14qr1c0eplgfvibi8t2hcd2; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Pragma: no-cache
Cache-Control: public, max-stale=13910400
Content-Length: 18
Content-Type: application/json;charset=utf-8
{"message":"Test"}
- Connection #0 to host localhost left intact
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With