Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
michael@0 | 1 | // 'timer' is global to avoid getting GCed which would cancel the timer |
michael@0 | 2 | var timer; |
michael@0 | 3 | const nsITimer = Components.interfaces.nsITimer; |
michael@0 | 4 | |
michael@0 | 5 | function attemptUnblock(s) { |
michael@0 | 6 | try { |
michael@0 | 7 | let blockedResponse = null; |
michael@0 | 8 | getObjectState("bug503481_" + s, function(x) {blockedResponse = x.wrappedJSObject.r}); |
michael@0 | 9 | blockedResponse.finish(); |
michael@0 | 10 | setObjectState("bug503481_" + s, null); |
michael@0 | 11 | } catch(e) { |
michael@0 | 12 | dump("unable to unblock " + s + "retrying in half a second\n"); |
michael@0 | 13 | timer = Components.classes["@mozilla.org/timer;1"] |
michael@0 | 14 | .createInstance(nsITimer); |
michael@0 | 15 | timer.initWithCallback(function () { attemptUnblock(s) }, 500, nsITimer.TYPE_ONE_SHOT); |
michael@0 | 16 | } |
michael@0 | 17 | } |
michael@0 | 18 | |
michael@0 | 19 | function handleRequest(request, response) |
michael@0 | 20 | { |
michael@0 | 21 | var query = {}; |
michael@0 | 22 | request.queryString.split('&').forEach(function (val) { |
michael@0 | 23 | var [name, value] = val.split('='); |
michael@0 | 24 | query[name] = unescape(value); |
michael@0 | 25 | }); |
michael@0 | 26 | |
michael@0 | 27 | dump("processing:" + request.queryString + "\n"); |
michael@0 | 28 | |
michael@0 | 29 | if (query.unblock) { |
michael@0 | 30 | attemptUnblock(query.unblock); |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | if (query.blockOn) { |
michael@0 | 34 | response.processAsync(); |
michael@0 | 35 | x = { r: response, QueryInterface: function(iid) { return this } }; |
michael@0 | 36 | x.wrappedJSObject = x; |
michael@0 | 37 | setObjectState("bug503481_" + query.blockOn, x); |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | response.setHeader("Cache-Control", "no-cache", false); |
michael@0 | 41 | response.setHeader("Content-Type", "text/plain", false); |
michael@0 | 42 | response.write(query.body); |
michael@0 | 43 | } |