了解If-Modified-Since HTTP Header [英] Understand If-Modified-Since HTTP Header
问题描述
我正在寻找一个试图使用请求对象的 If-Modified-Since
标头的缓存库。问题是这个标题永远不会被设置,它总是空白的,这对我来说是有意义的,看看它是如何请求。
I am looking at a Caching library that is trying to use the If-Modified-Since
header of a request object. The problem is this header never gets set, it is always blank which makes sense to me seeing how it is a REQUEST.
如何强制请求拥有 If-Modified-Since
标题?或者我是这样做的。
How can you force a request to have a If-Modified-Since
header? Or am I way off for what this does.
这是我所指的功能。
public function isNotModified(Request $request)
{
$lastModified = $request->headers->get('If-Modified-Since');
$notModified = false;
if ($etags = $request->getEtags()) {
$notModified = (in_array($this->getEtag(), $etags) || in_array('*', $etags)) && (!$lastModified || $this->headers->get('Last-Modified') == $lastModified);
} elseif ($lastModified) {
$notModified = $lastModified == $this->headers->get('Last-Modified');
}
if ($notModified) {
$this->setNotModified();
}
return $notModified;
}
推荐答案
If-Modified-Since
如果客户端已经拥有获得的资源以及具有 <的响应,那么这是有意义的code> Last-Modified 标题与标题相结合,允许浏览器缓存,如 Cache-Control
和/或 Pragma
包含 public
的值。
此外,我注意到一些浏览器在原始响应中还包含 If-Modified-Since
时 ETag
标题。浏览器将使用 If-None-Match
进行测试。
Also, I've noticed that some browsers does not include If-Modified-Since
when the original response also contained an ETag
header. The browser will instead use If-None-Match
to test it.
- Caching tutorial for web authors and web masters
这篇关于了解If-Modified-Since HTTP Header的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!