简体   繁体   English

Slim v3复制缓存控制头

[英]Slim v3 duplicates cache-control header

I have to return a specific cache-control header ( Cache-Control: public, max-stale=13910400 ) but when run this, I get this: 我必须返回一个特定的缓存控制头( Cache-Control: public, max-stale=13910400 ),但是当运行它时,我得到这个: 卷曲-v

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 CURL输出

C:\\Users\\Glenn>curl -X GET -v http://localhost/vms2/public/test C:\\ Users \\ Glenn> curl -X GET -v http:// localhost / vms2 / public / test

HTTP/1.1 200 OK HTTP / 1.1 200好的

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 日期:2016年9月13日星期二19:04:42 GMT *服务器Apache / 2.4.10(Win32)OpenSSL / 1.0.1i PHP / 5.6.3未列入黑名单

Server: Apache/2.4.10 (Win32) OpenSSL/1.0.1i PHP/5.6.3 服务器:Apache / 2.4.10(Win32)OpenSSL / 1.0.1i PHP / 5.6.3

X-Powered-By: PHP/5.6.3 X-Powered-By:PHP / 5.6.3

Set-Cookie: VMS2=2qf14qr1c0eplgfvibi8t2hcd2; Set-Cookie:VMS2 = 2qf14qr1c0eplgfvibi8t2hcd2; path=/ 路径= /

Expires: Thu, 19 Nov 1981 08:52:00 GMT 到期日:1981年11月19日星期四08:52:00 GMT

Pragma: no-cache Pragma:没有缓存

Cache-Control: public, max-stale=13910400 Cache-Control:public,max-stale = 13910400

Content-Length: 18 内容长度:18

Content-Type: application/json;charset=utf-8 Content-Type:application / json; charset = utf-8

{"message":"Test"} { “消息”: “测试”}

  • Connection #0 to host localhost left intact 连接#0到主机localhost保持不变

从代码中删除缓存控件,并在.htaccess文件中添加以下代码

<filesMatch "\\\\.(html|htm|php)$"> Header set Cache-Control "max-age=1, private, must-revalidate" </filesMatch>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM