mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 812167 - Redirect Responses are Cached to disk despite Cache-control: no-store, Expires: -1, r=michal
This commit is contained in:
parent
5ca57198bf
commit
65b52d00f6
@ -1350,6 +1350,8 @@ nsHttpChannel::ContinueProcessResponse(nsresult rv)
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
UpdateInhibitPersistentCachingFlag();
|
||||
|
||||
InitCacheEntry();
|
||||
CloseCacheEntry(false);
|
||||
|
||||
|
@ -77,3 +77,36 @@ function get_device_entry_count(device) {
|
||||
|
||||
return entry_count;
|
||||
}
|
||||
|
||||
function asyncCheckCacheEntryPresence(key, sessionName, storagePolicy, shouldExist, doomOnExpire, continuation)
|
||||
{
|
||||
var listener =
|
||||
{
|
||||
QueryInterface : function(iid)
|
||||
{
|
||||
if (iid.equals(Components.interfaces.nsICacheListener))
|
||||
return this;
|
||||
throw Components.results.NS_NOINTERFACE;
|
||||
},
|
||||
onCacheEntryAvailable : function(descriptor, accessGranted, status)
|
||||
{
|
||||
if (shouldExist) {
|
||||
dump("TEST-INFO | checking cache key " + key + " exists @ " + sessionName);
|
||||
do_check_eq(status, Cr.NS_OK);
|
||||
do_check_true(!!descriptor);
|
||||
} else {
|
||||
dump("TEST-INFO | checking cache key " + key + " doesn't exist @ " + sessionName);
|
||||
do_check_eq(status, Cr.NS_ERROR_CACHE_KEY_NOT_FOUND);
|
||||
do_check_null(descriptor);
|
||||
}
|
||||
continuation();
|
||||
}
|
||||
};
|
||||
|
||||
var service = Cc["@mozilla.org/network/cache-service;1"].getService(Ci.nsICacheService);
|
||||
var session = service.createSession(sessionName,
|
||||
storagePolicy,
|
||||
true);
|
||||
session.doomEntriesIfExpired = doomOnExpire;
|
||||
session.asyncOpenCacheEntry(key, Ci.nsICache.ACCESS_READ, listener);
|
||||
}
|
||||
|
96
netwerk/test/unit/test_bug812167.js
Normal file
96
netwerk/test/unit/test_bug812167.js
Normal file
@ -0,0 +1,96 @@
|
||||
const Cc = Components.classes;
|
||||
const Ci = Components.interfaces;
|
||||
const Cu = Components.utils;
|
||||
const Cr = Components.results;
|
||||
|
||||
Cu.import("resource://testing-common/httpd.js");
|
||||
|
||||
/*
|
||||
- get 302 with Cache-control: no-store
|
||||
- check cache entry for the 302 response is cached only in memory device
|
||||
- get 302 with Expires: -1
|
||||
- check cache entry for the 302 response is not cached at all
|
||||
*/
|
||||
|
||||
var httpserver = null;
|
||||
// Need to randomize, because apparently no one clears our cache
|
||||
var randomPath1 = "/redirect-no-store/" + Math.random();
|
||||
var randomURI1 = "http://localhost:4444" + randomPath1;
|
||||
var randomPath2 = "/redirect-expires-past/" + Math.random();
|
||||
var randomURI2 = "http://localhost:4444" + randomPath2;
|
||||
|
||||
function make_channel(url, callback, ctx) {
|
||||
var ios = Cc["@mozilla.org/network/io-service;1"].
|
||||
getService(Ci.nsIIOService);
|
||||
return ios.newChannel(url, "", null);
|
||||
}
|
||||
|
||||
const responseBody = "response body";
|
||||
|
||||
function redirectHandler_NoStore(metadata, response)
|
||||
{
|
||||
response.setStatusLine(metadata.httpVersion, 302, "Found");
|
||||
response.setHeader("Location", "http://localhost:4444/content", false);
|
||||
response.setHeader("Cache-control", "no-store");
|
||||
return;
|
||||
}
|
||||
|
||||
function redirectHandler_ExpiresInPast(metadata, response)
|
||||
{
|
||||
response.setStatusLine(metadata.httpVersion, 302, "Found");
|
||||
response.setHeader("Location", "http://localhost:4444/content", false);
|
||||
response.setHeader("Expires", "-1");
|
||||
return;
|
||||
}
|
||||
|
||||
function contentHandler(metadata, response)
|
||||
{
|
||||
response.setHeader("Content-Type", "text/plain");
|
||||
response.bodyOutputStream.write(responseBody, responseBody.length);
|
||||
}
|
||||
|
||||
function check_response(path, request, buffer, expectedExpiration, continuation)
|
||||
{
|
||||
do_check_eq(buffer, responseBody);
|
||||
// Check the redirect response has been cached only in memory and not on disk
|
||||
asyncCheckCacheEntryPresence(path, "HTTP", Ci.nsICache.STORE_ON_DISK, false, expectedExpiration, function() {
|
||||
asyncCheckCacheEntryPresence(path, "HTTP", Ci.nsICache.STORE_IN_MEMORY, !expectedExpiration, expectedExpiration, continuation);
|
||||
});
|
||||
}
|
||||
|
||||
function run_test_no_store()
|
||||
{
|
||||
var chan = make_channel(randomURI1);
|
||||
chan.asyncOpen(new ChannelListener(function(request, buffer) {
|
||||
// Cache-control: no-store response should only be found in the memory cache.
|
||||
check_response(randomURI1, request, buffer, false, run_test_expires_past);
|
||||
}, null), null);
|
||||
}
|
||||
|
||||
function run_test_expires_past()
|
||||
{
|
||||
var chan = make_channel(randomURI2);
|
||||
chan.asyncOpen(new ChannelListener(function(request, buffer) {
|
||||
// Expires: -1 response should not be found in any cache.
|
||||
check_response(randomURI2, request, buffer, true, finish_test);
|
||||
}, null), null);
|
||||
}
|
||||
|
||||
function finish_test()
|
||||
{
|
||||
httpserver.stop(do_test_finished);
|
||||
}
|
||||
|
||||
function run_test()
|
||||
{
|
||||
do_get_profile();
|
||||
|
||||
httpserver = new HttpServer();
|
||||
httpserver.registerPathHandler(randomPath1, redirectHandler_NoStore);
|
||||
httpserver.registerPathHandler(randomPath2, redirectHandler_ExpiresInPast);
|
||||
httpserver.registerPathHandler("/content", contentHandler);
|
||||
httpserver.start(4444);
|
||||
|
||||
run_test_no_store();
|
||||
do_test_pending();
|
||||
}
|
@ -208,3 +208,4 @@ run-if = hasNode
|
||||
[test_offlinecache_custom-directory.js]
|
||||
[test_bug767025.js]
|
||||
[test_bug826063.js]
|
||||
[test_bug812167.js]
|
||||
|
Loading…
Reference in New Issue
Block a user