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