Overcome non-cacheability of pages on Firefox
I'm trying to build an extension to Firefox to get a page from a web server and put it in the browser's cache, so that when the user asks for that link, it'll be retrieved directly from the cache, 开发者_如何学Pythoninstead of asking to the original web server.
But I'm having trouble with some pages which put headers to avoid cacheability, such as "Cache-control: must-revalidate", "Cache-control: no-store", "Cache-control: no-cache" and "Pragma: no-cache".
I'm trying to overwrite those headers with nsIHttpChannel's setResponseHeader when the page arrives. But the headers are not changed in the corresponding cache entry. Then I try nsICacheEntryDescriptor's setMetaDataElement to change the metadata key "response-head". Though the data is changed, the page still is being retrieved from the original web server.
Does anyone know how to overcome this problem and make the pages be loaded from Firefox's cache? Is this possible?
Thanks in advance.
I was using XMLHttpRequest to retrieve the page, and the problem was that I changed the response headers in the "onreadystatechange" function I made.
Alternatevely, I used the observer for "http-on-examine-response", and altered the response headers in the "observe" method. The change is now being kept by the cache.
I've got the insight by looking at the BetterCache Firefox extension's code.
精彩评论