gpt4 book ai didi

google-chrome - 覆盖 HTTP 响应中的 "cache-control"值

转载 作者:行者123 更新时间:2023-12-04 08:26:25 27 4
gpt4 key购买 nike

我有一个网页,当我访问 Material 时返回以下标题:

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这样 Material 实际上被缓存而不是浪费带宽。

我有以下示例代码:
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

但是根据我试图检查的所有内容,我看不到任何证据表明这确实发生了:
  • cache不包含此文件的条目
  • Network Developer Console 中的选项卡显示 HTTP 响应完全没有变化(我已经尝试将其更改为即使是微不足道的修改,只是为了确保它不是错误,但仍然没有变化)。

  • 我能找到的唯一真正的提示是 this question这表明我的方法仍然有效,而这一段关于 webRequest API documentation这表明这不起作用(但不能解释为什么我无法获得任何更改):

    Note that the web request API presents an abstraction of the network stack to the extension. Internally, one URL request can be split into several HTTP requests (for example to fetch individual byte ranges from a large file) or can be handled by the network stack without communicating with the network. For this reason, the API does not provide the final HTTP headers that are sent to the network. For example, all headers that are related to caching are invisible to the extension.



    没有任何效果(我根本无法修改 HTTP response header)所以我认为这是我的首要问题。

    关于我可能出错的地方或如何找到这里出了什么问题的任何建议?

    如果不可能,还有其他方法可以实现我想要实现的目标吗?

    最佳答案

    我最近花了几个小时尝试缓存文件,发现 chrome.webRequest chrome.declarativeWebRequest API 不能 强制缓存资源。绝不。
    Cache-Control (和其他)响应头可以改变,但它只会在 getResponseHeader 中可见方法。不在缓存行为中。

    关于google-chrome - 覆盖 HTTP 响应中的 "cache-control"值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17382152/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com