3 const { HttpServer
} = ChromeUtils
.importESModule(
4 "resource://testing-common/httpd.sys.mjs"
7 ChromeUtils
.defineLazyGetter(this, "URL", function () {
8 return "http://localhost:" + httpServer
.identity
.primaryPort
;
11 var httpServer
= null;
12 // Need to randomize, because apparently no one clears our cache
13 var randomPath
= "/redirect/" + Math
.random();
15 ChromeUtils
.defineLazyGetter(this, "randomURI", function () {
16 return URL
+ randomPath
;
19 function make_channel(url
) {
20 return NetUtil
.newChannel({ uri
: url
, loadUsingSystemPrincipal
: true });
23 const responseBody
= "response body";
25 function redirectHandler(metadata
, response
) {
26 response
.setStatusLine(metadata
.httpVersion
, 301, "Moved");
27 response
.setHeader("Location", URL
+ "/content", false);
28 response
.setHeader("Cache-control", "max-age=1000", false);
31 function contentHandler(metadata
, response
) {
32 response
.setHeader("Content-Type", "text/plain");
33 response
.bodyOutputStream
.write(responseBody
, responseBody
.length
);
36 function firstTimeThrough(request
, buffer
) {
37 Assert
.equal(buffer
, responseBody
);
38 var chan
= make_channel(randomURI
);
39 chan
.asyncOpen(new ChannelListener(secondTimeThrough
, null));
42 function secondTimeThrough(request
, buffer
) {
43 Assert
.equal(buffer
, responseBody
);
44 var chan
= make_channel(randomURI
);
45 chan
.loadFlags
|= Ci
.nsIRequest
.LOAD_FROM_CACHE
;
46 chan
.notificationCallbacks
= new ChannelEventSink(ES_ABORT_REDIRECT
);
47 chan
.asyncOpen(new ChannelListener(finish_test
, null, CL_EXPECT_FAILURE
));
50 function finish_test(request
, buffer
) {
51 Assert
.equal(buffer
, "");
52 httpServer
.stop(do_test_finished
);
56 httpServer
= new HttpServer();
57 httpServer
.registerPathHandler(randomPath
, redirectHandler
);
58 httpServer
.registerPathHandler("/content", contentHandler
);
61 var chan
= make_channel(randomURI
);
62 chan
.asyncOpen(new ChannelListener(firstTimeThrough
, null));