file_bug503481.sjs (1347B)
1 // 'timer' is global to avoid getting GCed which would cancel the timer 2 var timer; 3 const nsITimer = Ci.nsITimer; 4 5 function attemptUnblock(s) { 6 try { 7 let blockedResponse = null; 8 getObjectState("bug503481_" + s, function (x) { 9 blockedResponse = x.wrappedJSObject.r; 10 }); 11 blockedResponse.finish(); 12 setObjectState("bug503481_" + s, null); 13 } catch (e) { 14 dump("unable to unblock " + s + "retrying in half a second\n"); 15 timer = Cc["@mozilla.org/timer;1"].createInstance(nsITimer); 16 timer.initWithCallback( 17 function () { 18 attemptUnblock(s); 19 }, 20 500, 21 nsITimer.TYPE_ONE_SHOT 22 ); 23 } 24 } 25 26 function handleRequest(request, response) { 27 var query = {}; 28 request.queryString.split("&").forEach(function (val) { 29 var [name, value] = val.split("="); 30 query[name] = unescape(value); 31 }); 32 33 dump("processing:" + request.queryString + "\n"); 34 35 if (query.unblock) { 36 attemptUnblock(query.unblock); 37 } 38 39 if (query.blockOn) { 40 response.processAsync(); 41 x = { 42 r: response, 43 QueryInterface(iid) { 44 return this; 45 }, 46 }; 47 x.wrappedJSObject = x; 48 setObjectState("bug503481_" + query.blockOn, x); 49 } 50 51 response.setHeader("Cache-Control", "no-cache", false); 52 response.setHeader("Content-Type", "text/plain", false); 53 response.write(query.body); 54 }