2 // Verify that we hit the net if we discover a cycle of redirects
8 const { HttpServer } = ChromeUtils.importESModule(
9 "resource://testing-common/httpd.sys.mjs"
12 var httpserver = new HttpServer();
15 function setupChannel(suffix) {
16 var chan = NetUtil.newChannel({
17 uri: "http://localhost:" + httpserver.identity.primaryPort + suffix,
18 loadUsingSystemPrincipal: true,
20 var httpChan = chan.QueryInterface(Ci.nsIHttpChannel);
21 httpChan.requestMethod = "GET";
25 function checkValueAndTrigger(request, data, ctx) {
26 Assert.equal("Ok", data);
27 httpserver.stop(do_test_finished);
31 httpserver.registerPathHandler("/redirect1", redirectHandler1);
32 httpserver.registerPathHandler("/redirect2", redirectHandler2);
36 evict_cache_entries();
39 var channel = setupChannel("/redirect1");
40 channel.asyncOpen(new ChannelListener(checkValueAndTrigger, null));
45 function redirectHandler1(metadata, response) {
46 // first time we return a cacheable 302 pointing to next redirect
48 response.setStatusLine(metadata.httpVersion, 302, "Found");
49 response.setHeader("Cache-Control", "max-age=600", false);
50 response.setHeader("Location", "/redirect2", false);
52 // next time called we return 200
54 response.setStatusLine(metadata.httpVersion, 200, "Ok");
55 response.setHeader("Cache-Control", "max-age=600", false);
56 response.setHeader("Content-Type", "text/plain");
57 response.bodyOutputStream.write("Ok", "Ok".length);
62 function redirectHandler2(metadata, response) {
63 response.setStatusLine(metadata.httpVersion, 302, "Found");
64 response.setHeader("Cache-Control", "max-age=600", false);
65 response.setHeader("Location", "/redirect1", false);