2011-06-11 18:57:10 +04:00
|
|
|
//
|
|
|
|
// If a response to a non-safe HTTP request-method contains the Location- or
|
|
|
|
// Content-Location header, we must make sure to invalidate any cached entry
|
|
|
|
// representing the URIs pointed to by either header. RFC 2616 section 13.10
|
|
|
|
//
|
|
|
|
// This test uses 3 URIs: "/post" is the target of a POST-request and always
|
|
|
|
// redirects (301) to "/redirect". The URIs "/redirect" and "/cl" both counts
|
|
|
|
// the number of loads from the server (handler). The response from "/post"
|
|
|
|
// always contains the headers "Location: /redirect" and "Content-Location:
|
|
|
|
// /cl", whose cached entries are to be invalidated. The tests verifies that
|
|
|
|
// "/redirect" and "/cl" are loaded from server the expected number of times.
|
|
|
|
//
|
2012-08-14 18:06:04 +04:00
|
|
|
|
2020-04-07 19:00:03 +03:00
|
|
|
"use strict";
|
|
|
|
|
2019-01-17 21:18:31 +03:00
|
|
|
const { HttpServer } = ChromeUtils.import("resource://testing-common/httpd.js");
|
2011-06-11 18:57:10 +04:00
|
|
|
|
|
|
|
var httpserv;
|
|
|
|
|
|
|
|
function setupChannel(path) {
|
2015-12-22 03:29:26 +03:00
|
|
|
return NetUtil.newChannel({
|
|
|
|
uri: path,
|
|
|
|
loadUsingSystemPrincipal: true,
|
|
|
|
}).QueryInterface(Ci.nsIHttpChannel);
|
2011-06-11 18:57:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Verify that Content-Location-URI has been loaded once, load post_target
|
|
|
|
function InitialListener() {}
|
|
|
|
InitialListener.prototype = {
|
2019-06-21 23:13:40 +03:00
|
|
|
onStartRequest(request) {},
|
|
|
|
onStopRequest(request, status) {
|
2011-06-11 18:57:10 +04:00
|
|
|
Assert.equal(1, numberOfCLHandlerCalls);
|
|
|
|
executeSoon(function() {
|
2013-07-19 21:19:28 +04:00
|
|
|
var channel = setupChannel(
|
|
|
|
"http://localhost:" + httpserv.identity.primaryPort + "/post"
|
|
|
|
);
|
2014-03-18 20:36:18 +04:00
|
|
|
channel.requestMethod = "POST";
|
2019-02-12 19:08:25 +03:00
|
|
|
channel.asyncOpen(new RedirectingListener());
|
2011-06-11 18:57:10 +04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
// Verify that Location-URI has been loaded once, reload post_target
|
|
|
|
function RedirectingListener() {}
|
|
|
|
RedirectingListener.prototype = {
|
2019-06-21 23:13:40 +03:00
|
|
|
onStartRequest(request) {},
|
|
|
|
onStopRequest(request, status) {
|
2011-06-11 18:57:10 +04:00
|
|
|
Assert.equal(1, numberOfHandlerCalls);
|
|
|
|
executeSoon(function() {
|
2013-07-19 21:19:28 +04:00
|
|
|
var channel = setupChannel(
|
|
|
|
"http://localhost:" + httpserv.identity.primaryPort + "/post"
|
|
|
|
);
|
2014-03-18 20:36:18 +04:00
|
|
|
channel.requestMethod = "POST";
|
2019-02-12 19:08:25 +03:00
|
|
|
channel.asyncOpen(new VerifyingListener());
|
2011-06-11 18:57:10 +04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
// Verify that Location-URI has been loaded twice (cached entry invalidated),
|
|
|
|
// reload Content-Location-URI
|
|
|
|
function VerifyingListener() {}
|
|
|
|
VerifyingListener.prototype = {
|
2019-06-21 23:13:40 +03:00
|
|
|
onStartRequest(request) {},
|
|
|
|
onStopRequest(request, status) {
|
2011-06-11 18:57:10 +04:00
|
|
|
Assert.equal(2, numberOfHandlerCalls);
|
2013-07-19 21:19:28 +04:00
|
|
|
var channel = setupChannel(
|
|
|
|
"http://localhost:" + httpserv.identity.primaryPort + "/cl"
|
|
|
|
);
|
2019-02-12 19:08:25 +03:00
|
|
|
channel.asyncOpen(new FinalListener());
|
2011-06-11 18:57:10 +04:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
// Verify that Location-URI has been loaded twice (cached entry invalidated),
|
|
|
|
// stop test
|
|
|
|
function FinalListener() {}
|
|
|
|
FinalListener.prototype = {
|
2019-06-21 23:13:40 +03:00
|
|
|
onStartRequest(request) {},
|
|
|
|
onStopRequest(request, status) {
|
2011-06-11 18:57:10 +04:00
|
|
|
Assert.equal(2, numberOfCLHandlerCalls);
|
|
|
|
httpserv.stop(do_test_finished);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
function run_test() {
|
2012-08-14 18:06:04 +04:00
|
|
|
httpserv = new HttpServer();
|
2011-06-11 18:57:10 +04:00
|
|
|
httpserv.registerPathHandler("/cl", content_location);
|
|
|
|
httpserv.registerPathHandler("/post", post_target);
|
|
|
|
httpserv.registerPathHandler("/redirect", redirect_target);
|
2013-07-19 21:19:28 +04:00
|
|
|
httpserv.start(-1);
|
2011-06-11 18:57:10 +04:00
|
|
|
|
|
|
|
// Clear cache
|
2012-06-13 01:23:32 +04:00
|
|
|
evict_cache_entries();
|
2011-06-11 18:57:10 +04:00
|
|
|
|
|
|
|
// Load Content-Location URI into cache and start the chain of loads
|
2013-07-19 21:19:28 +04:00
|
|
|
var channel = setupChannel(
|
|
|
|
"http://localhost:" + httpserv.identity.primaryPort + "/cl"
|
|
|
|
);
|
2019-02-12 19:08:25 +03:00
|
|
|
channel.asyncOpen(new InitialListener());
|
2011-06-11 18:57:10 +04:00
|
|
|
|
|
|
|
do_test_pending();
|
|
|
|
}
|
|
|
|
|
|
|
|
var numberOfCLHandlerCalls = 0;
|
|
|
|
function content_location(metadata, response) {
|
|
|
|
numberOfCLHandlerCalls++;
|
|
|
|
response.setStatusLine(metadata.httpVersion, 200, "Ok");
|
|
|
|
response.setHeader("Cache-Control", "max-age=360000", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
function post_target(metadata, response) {
|
|
|
|
response.setStatusLine(metadata.httpVersion, 301, "Moved Permanently");
|
|
|
|
response.setHeader("Location", "/redirect", false);
|
|
|
|
response.setHeader("Content-Location", "/cl", false);
|
|
|
|
response.setHeader("Cache-Control", "max-age=360000", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
var numberOfHandlerCalls = 0;
|
|
|
|
function redirect_target(metadata, response) {
|
|
|
|
numberOfHandlerCalls++;
|
|
|
|
response.setStatusLine(metadata.httpVersion, 200, "Ok");
|
|
|
|
response.setHeader("Cache-Control", "max-age=360000", false);
|
|
|
|
}
|