3 const { HttpServer } = ChromeUtils.importESModule(
4 "resource://testing-common/httpd.sys.mjs"
7 var httpProtocolHandler = Cc[
8 "@mozilla.org/network/protocol;1?name=http"
9 ].getService(Ci.nsIHttpProtocolHandler);
11 var httpserver = new HttpServer();
13 var expectedOnStopRequests = 3;
15 function setupChannel(suffix, xRequest, flags) {
16 var chan = NetUtil.newChannel({
17 uri: "http://localhost:" + httpserver.identity.primaryPort + suffix,
18 loadUsingSystemPrincipal: true,
21 chan.loadFlags |= flags;
24 var httpChan = chan.QueryInterface(Ci.nsIHttpChannel);
25 httpChan.setRequestHeader("x-request", xRequest, false);
30 function Listener(response) {
31 this._response = response;
33 Listener.prototype = {
37 QueryInterface: ChromeUtils.generateQI([
42 onStartRequest(request) {
45 onDataAvailable(request, stream, offset, count) {
46 this._buffer = this._buffer.concat(read_stream(stream, count));
48 onStopRequest(request, status) {
49 Assert.equal(this._buffer, this._response);
50 if (--expectedOnStopRequests == 0) {
51 do_timeout(10, function () {
52 httpserver.stop(do_test_finished);
59 httpserver.registerPathHandler("/bug596443", handler);
62 Services.prefs.setBoolPref("network.http.rcwn.enabled", false);
64 // make sure we have a profile so we can use the disk-cache
68 evict_cache_entries();
70 httpProtocolHandler.EnsureHSTSDataReady().then(function () {
71 var ch0 = setupChannel(
74 Ci.nsIRequest.LOAD_BYPASS_CACHE
76 ch0.asyncOpen(new Listener("Response0"));
78 var ch1 = setupChannel(
81 Ci.nsIRequest.LOAD_BYPASS_CACHE
83 ch1.asyncOpen(new Listener("Response1"));
85 var ch2 = setupChannel("/bug596443", "Should not be used");
86 ch2.asyncOpen(new Listener("Response1")); // Note param: we expect this to come from cache
92 function triggerHandlers() {
93 do_timeout(100, handlers[1]);
94 do_timeout(100, handlers[0]);
98 function handler(metadata, response) {
99 var func = function (body) {
101 response.setStatusLine(metadata.httpVersion, 200, "Ok");
102 response.setHeader("Content-Type", "text/plain", false);
103 response.setHeader("Content-Length", "" + body.length, false);
104 response.setHeader("Cache-Control", "max-age=600", false);
105 response.bodyOutputStream.write(body, body.length);
110 response.processAsync();
111 var request = metadata.getHeader("x-request");
112 handlers.push(func(request));
114 if (handlers.length > 1) {