michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: // The timer never fires if it's not declared and set to this variable outside michael@0: // handleRequest, as if it's getting GC'ed when handleRequest's scope goes away. michael@0: // Shouldn't the timer thread hold a strong reference to it? michael@0: var timer; michael@0: michael@0: function handleRequest(req, resp) { michael@0: resp.processAsync(); michael@0: resp.setHeader("Cache-Control", "no-cache, no-store", false); michael@0: resp.setHeader("Content-Type", "text/html;charset=utf-8", false); michael@0: michael@0: let opts = {}; michael@0: try { michael@0: opts = JSON.parse(decodeURIComponent(req.queryString)); michael@0: } michael@0: catch (err) {} michael@0: michael@0: if (opts.setRedCookie) michael@0: resp.setHeader("Set-Cookie", "red", false); michael@0: michael@0: if (opts.setGreenCookie) michael@0: resp.setHeader("Set-Cookie", "green", false); michael@0: michael@0: if (req.hasHeader("Cookie") && michael@0: req.getHeader("Cookie").split(";").indexOf("red") >= 0) { michael@0: resp.write(''); michael@0: resp.finish(); michael@0: return; michael@0: } michael@0: michael@0: if (req.hasHeader("Cookie") && michael@0: req.getHeader("Cookie").split(";").indexOf("green") >= 0) { michael@0: resp.write(''); michael@0: resp.finish(); michael@0: return; michael@0: } michael@0: michael@0: if (opts.redirect) { michael@0: resp.setHeader("Location", opts.redirect); michael@0: resp.setStatusLine(null, 303, null); michael@0: resp.finish(); michael@0: return; michael@0: } michael@0: michael@0: if (opts.wait) { michael@0: resp.write("Waiting " + opts.wait + " ms... "); michael@0: timer = Components.classes["@mozilla.org/timer;1"]. michael@0: createInstance(Components.interfaces.nsITimer); michael@0: timer.init(function ding() { michael@0: resp.write("OK!"); michael@0: resp.finish(); michael@0: }, opts.wait, Components.interfaces.nsITimer.TYPE_ONE_SHOT); michael@0: return; michael@0: } michael@0: michael@0: resp.write("
" + JSON.stringify(opts, undefined, 2) + "
"); michael@0: resp.finish(); michael@0: }