我有一个网页,当我访问材料时,该网页返回以下标头:
HTTP/1.1 200 OK
Date: Sat, 29 Jun 2013 15:57:25 GMT
Server: Apache
Content-Length: 2247515
Cache-Control: no-cache, no-store, must-revalidate, max-age=-1
Pragma: no-cache, no-store
Expires: -1
Connection: close
使用chrome扩展,我想修改这个response header
以便材料实际上被缓存而不是浪费带宽。
我有以下示例代码:
chrome.webRequest.onHeadersReceived.addListener(function(details)
{
// Delete the required elements
removeHeader(details.responseHeaders, 'pragma');
removeHeader(details.responseHeaders, 'expires');
// Modify cache-control
updateHeader(details.responseHeaders, 'cache-control', 'max-age=3600;')
console.log(details.url);
console.log(details.responseHeaders);
return{responseHeaders: details.responseHeaders};
},
{urls: ["<all_urls>"]}, ['blocking', 'responseHeaders']
);
它正确地将标头修改为类似这样的内容(基于 console.log() 输出):
HTTP/1.1 200 OK
Date: Sat, 29 Jun 2013 15:57:25 GMT
Server: Apache
Content-Length: 2247515
Cache-Control: max-age=3600
Connection: close
但根据我试图检查的一切,我看不到任何证据表明这确实发生了:
- The
cache
不包含该文件的条目
- The
Network
选项卡中的Developer Console
显示 HTTP 响应没有任何变化(我尝试将其更改为甚至是微不足道的修改,只是为了确保它不是错误,但仍然没有变化)。
我能找到的唯一真正的提示是这个问题这表明我的方法仍然有效,这一段关于webRequest API 文档这表明这行不通(但没有解释为什么我无法得到任何改变):
请注意,Web 请求 API 呈现了网络的抽象
堆栈到扩展。在内部,一个 URL 请求可以分为
多个 HTTP 请求(例如获取单个字节范围
来自大文件)或者可以由网络堆栈处理,无需
与网络通信。因此,API 不
提供发送到网络的最终 HTTP 标头。为了
例如,所有与缓存相关的标头对于
扩大。
没有任何效果(我无法修改HTTP response header
完全)所以我认为这是我首先关心的问题。
关于我可能出错的地方或者如何找到这里出错的地方有什么建议吗?
如果不可能,还有其他方法可以实现我想要实现的目标吗?