michael@0: // 'timer' is global to avoid getting GCed which would cancel the timer michael@0: var timer; michael@0: const nsITimer = Components.interfaces.nsITimer; michael@0: michael@0: function attemptUnblock(s) { michael@0: try { michael@0: let blockedResponse = null; michael@0: getObjectState("bug503481_" + s, function(x) {blockedResponse = x.wrappedJSObject.r}); michael@0: blockedResponse.finish(); michael@0: setObjectState("bug503481_" + s, null); michael@0: } catch(e) { michael@0: dump("unable to unblock " + s + "retrying in half a second\n"); michael@0: timer = Components.classes["@mozilla.org/timer;1"] michael@0: .createInstance(nsITimer); michael@0: timer.initWithCallback(function () { attemptUnblock(s) }, 500, nsITimer.TYPE_ONE_SHOT); michael@0: } michael@0: } michael@0: michael@0: function handleRequest(request, response) michael@0: { michael@0: var query = {}; michael@0: request.queryString.split('&').forEach(function (val) { michael@0: var [name, value] = val.split('='); michael@0: query[name] = unescape(value); michael@0: }); michael@0: michael@0: dump("processing:" + request.queryString + "\n"); michael@0: michael@0: if (query.unblock) { michael@0: attemptUnblock(query.unblock); michael@0: } michael@0: michael@0: if (query.blockOn) { michael@0: response.processAsync(); michael@0: x = { r: response, QueryInterface: function(iid) { return this } }; michael@0: x.wrappedJSObject = x; michael@0: setObjectState("bug503481_" + query.blockOn, x); michael@0: } michael@0: michael@0: response.setHeader("Cache-Control", "no-cache", false); michael@0: response.setHeader("Content-Type", "text/plain", false); michael@0: response.write(query.body); michael@0: }