问题描述
对不起,可能是错误的标题.我正在编写一些代码来处理 If-Modified-Since 和 If-None-Match 请求作为缓存的一部分.除了 PHP 在标题之后返回一些内容(一个空行)之外,一切都很完美.页面内容应该是空的.我使用的代码是:
Sorry for the probably wrong title. I am writing some code to handle If-Modified-Since and If-None-Match requests as part of caching. Everything works perfect except for that PHP returns some content (an empty line) after the headers. The page content should be empty instead. The code that I am using is:
<?php
$lastmod = filemtime($f);
$etag = '"'.dechex($lastmod).'"';
if ($_SERVER['HTTP_IF_MODIFIED_SINCE'] == $last_mod || $_SERVER['HTTP_IF_NONE_MATCH'] == $etag) {
header('HTTP/1.1 304 Not Modified');
header('Content-Length: 0');
exit();
}
?>
推荐答案
终于解决了这个bug.Gzip 是罪魁祸首.由于我也在压缩对 If-Modified-Since 和 If-None-Match 请求的响应,因此 gzip 在响应中添加了一些字节(一种 gzip 标头).现在我停止了对 If-Modified-Since 和 If-None-Match 请求的 gzip 响应,它就像一个魅力.
Finally solved this bug. Gzip was the culprit. Since I was gzipping the responses to If-Modified-Since and If-None-Match requests too, gzip was adding a few bytes (kind of a gzip header) to the response. Now I have stopped gzipping responses to If-Modified-Since and If-None-Match requests, and it works like a charm.
这篇关于304未修改问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!



大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)