1 do_import_script("netwerk/test/httpserver/httpd.js");
4 // Need to randomize, because apparently no one clears our cache
5 var randomPath = "/redirect/" + Math.random();
6 var randomURI = "http://localhost:4444" + randomPath;
8 function make_channel(url, callback, ctx) {
9 var ios = Cc["@mozilla.org/network/io-service;1"].
10 getService(Ci.nsIIOService);
11 return ios.newChannel(url, "", null);
14 const responseBody = "response body";
16 function redirectHandler(metadata, response)
18 response.setStatusLine(metadata.httpVersion, 301, "Moved");
19 response.setHeader("Location", "http://localhost:4444/content", false);
23 function contentHandler(metadata, response)
25 response.setHeader("Content-Type", "text/plain");
26 response.bodyOutputStream.write(responseBody, responseBody.length);
29 function firstTimeThrough(request, buffer)
31 do_check_eq(buffer, responseBody);
32 var chan = make_channel(randomURI);
33 chan.loadFlags |= Ci.nsICachingChannel.LOAD_ONLY_FROM_CACHE;
34 chan.asyncOpen(new ChannelListener(finish_test, null), null);
37 function finish_test(request, buffer)
40 do_check_eq(buffer, responseBody);
46 httpserver = new nsHttpServer();
47 httpserver.registerPathHandler(randomPath, redirectHandler);
48 httpserver.registerPathHandler("/content", contentHandler);
49 httpserver.start(4444);
51 var chan = make_channel(randomURI);
52 chan.asyncOpen(new ChannelListener(firstTimeThrough, null), null);