我想和304响应一起发送什么标题? [英] What headers do I want to send together with a 304 response?
问题描述
header(HTTP / 1.1 304 Not Modified);
header(Expires:。gmdate(D,d M Y H:i:s,time()+ $ offset)。GMT);
这会确保浏览器不会发送另一个条件GET请求(也没有任何请求),直到$ offset时间已经用完了?
另外,其他标题呢? 我应该发送这样的标题吗?以及304:
header('Content-Type:text / html');
我必须发送:
header(Last-Modified:。$ modified);
header('Etag:'。$ etag);
为了确保浏览器在下次发生条件GET请求时发生$ runrun out或者只是保存旧的Last Modified和Etag值?
在发送304响应头文件时,我还应该注意其他事情吗?
这篇博文
为了驯服有条件的野兽,a>帮了我很大的忙。一段有趣的摘录(与Ben的答案部分矛盾)指出:
lockquote
如果一个正常的响应包含一个ETag头部,那么这个头部也必须包含在304响应中。
缓存头文件(Expires,Cache-Control,and / or Vary ),如果它们的值可能与先前的响应中发送的值不同。
完全按照 RFC 2616 sec 10.3.5 。
低于200请求...
HTTP / 1.1 200 OK
服务器:nginx / 0.8.52
日期:2010年11月18日星期四16:04:38 GMT
Content-Type:image / png
最后修改时间:星期四,15十月2009 02:04:11 GMT
过期时间:2010年12月31日星期四02:04:11 GMT
Cache-Control:max-age = 315360000
接受范围:字节
内容长度:6394
V ia:1.1 proxyIR.my.corporate.proxy.name:8080(IronPort-WSA / 6.3.3-015)
连接:保持活动状态
代理连接:保持活动状态
X -Junk:xxxxxxxxxxxxxxxx
...和其最佳的有效304对应字符。
HTTP / 1.1 304未修改
服务器:nginx / 0.8.52
日期:Thu,18 Nov 2010 16:10:35 GMT
过期时间:2011年12月31日星期四16:10:35 GMT
Cache-Control:max-age = 315360000
Via:1.1 proxyIR.my.corporate.proxy.name:8080( IronPort-WSA / 6.3.3-015)
连接:保持活动
代理连接:保持活动
X-Junk:xxxxxxxxxxx
请注意, Expires
标头最多为当前日期+一年
按照 RFC-2616 14.21 。
When I send a 304 response. How will the browser interpret other headers which I send together with the 304?
E.g.
header("HTTP/1.1 304 Not Modified");
header("Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT");
Will this make sure the browser will not send another conditional GET request (nor any request) until $offset time has "run out"?
Also, what about other headers?
Should I send headers like this together with the 304:
header('Content-Type: text/html');
Do I have to send:
header("Last-Modified:" . $modified);
header('Etag: ' . $etag);
To make sure the browser sends a conditional GET request the next time the $offset has "run out" or does it simply save the old Last Modified and Etag values?
Are there other things I should be aware about when sending a 304 response header?
This blog post helped me a lot in order to tame the "conditional get" beast.
An interesting excerpt (which partially contradicts Ben's answer) states that:
If a normal response would have included an ETag header, that header must also be included in the 304 response.
Cache headers (Expires, Cache-Control, and/or Vary), if their values might differ from those sent in a previous response.
This is in complete accordance with the RFC 2616 sec 10.3.5.
Below a 200 request...
HTTP/1.1 200 OK
Server: nginx/0.8.52
Date: Thu, 18 Nov 2010 16:04:38 GMT
Content-Type: image/png
Last-Modified: Thu, 15 Oct 2009 02:04:11 GMT
Expires: Thu, 31 Dec 2010 02:04:11 GMT
Cache-Control: max-age=315360000
Accept-Ranges: bytes
Content-Length: 6394
Via: 1.1 proxyIR.my.corporate.proxy.name:8080 (IronPort-WSA/6.3.3-015)
Connection: keep-alive
Proxy-Connection: keep-alive
X-Junk: xxxxxxxxxxxxxxxx
...And its optimal valid 304 counterpart.
HTTP/1.1 304 Not Modified
Server: nginx/0.8.52
Date: Thu, 18 Nov 2010 16:10:35 GMT
Expires: Thu, 31 Dec 2011 16:10:35 GMT
Cache-Control: max-age=315360000
Via: 1.1 proxyIR.my.corporate.proxy.name:8080 (IronPort-WSA/6.3.3-015)
Connection: keep-alive
Proxy-Connection: keep-alive
X-Junk: xxxxxxxxxxx
Notice that the Expires
header is at most Current Date + One Year
as per RFC-2616 14.21.
这篇关于我想和304响应一起发送什么标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!