该etag()
方法做了两件事:
- 将标头添加
ETag
到响应中
- 如果客户端发送
If-None-Match
带有值的标头,则发送 304 状态响应uniqueEtag12
因此,我认为您的请求不包含If-None-Match
标头。
示例代码:
索引.php:
<?php
require 'vendor/autoload.php';
$app = new \Slim\Slim();
$app->get('/hello', function () use ($app) {
$app->etag('1234');
echo "Hello world on " . date("Y-m-d H:i:s");
});
$app->run();
使用 curl 进行测试。
没有If-None-Match
标题:$ curl -i http://localhost:8888/hello
HTTP/1.1 200 OK
Host: localhost:8888
Connection: close
X-Powered-By: PHP/7.0.15
Content-type: text/html;charset=UTF-8
Etag: "1234"
Hello world on 2017-05-04 07:12:40
带有If-None-Match
标题:
$ curl -i http://localhost:8888/hello -H 'If-None-Match: "1234"'
HTTP/1.1 304 Not Modified
Host: localhost:8888
Connection: close
X-Powered-By: PHP/7.0.15
Etag: "1234"