3 const { HttpServer } = ChromeUtils.importESModule(
4 "resource://testing-common/httpd.sys.mjs"
7 var httpserver = new HttpServer();
10 { url: "/bug510359", server: "0", expected: "0" },
11 { url: "/bug510359", server: "1", expected: "1" },
14 function setupChannel(suffix, value) {
15 var chan = NetUtil.newChannel({
16 uri: "http://localhost:" + httpserver.identity.primaryPort + suffix,
17 loadUsingSystemPrincipal: true,
19 var httpChan = chan.QueryInterface(Ci.nsIHttpChannel);
20 httpChan.requestMethod = "GET";
21 httpChan.setRequestHeader("x-request", value, false);
22 httpChan.setRequestHeader("Cookie", "c=" + value, false);
26 function triggerNextTest() {
27 var channel = setupChannel(tests[index].url, tests[index].server);
28 channel.asyncOpen(new ChannelListener(checkValueAndTrigger, null));
31 function checkValueAndTrigger(request, data, ctx) {
32 Assert.equal(tests[index].expected, data);
34 if (index < tests.length - 1) {
38 httpserver.stop(do_test_finished);
43 httpserver.registerPathHandler("/bug510359", handler);
47 evict_cache_entries();
54 function handler(metadata, response) {
56 metadata.getHeader("If-Modified-Since");
57 response.setStatusLine(metadata.httpVersion, 500, "Failed");
58 var msg = "Client should not set If-Modified-Since header";
59 response.bodyOutputStream.write(msg, msg.length);
61 response.setStatusLine(metadata.httpVersion, 200, "Ok");
62 response.setHeader("Content-Type", "text/plain", false);
63 response.setHeader("Last-Modified", getDateString(-1), false);
64 response.setHeader("Vary", "Cookie", false);
65 var body = metadata.getHeader("x-request");
66 response.bodyOutputStream.write(body, body.length);
70 function getDateString(yearDelta) {
85 var days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
93 months[d.getUTCMonth()] +
95 (d.getUTCFullYear() + yearDelta) +