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 | const CC = Components.Constructor; |
michael@0 | 2 | const BinaryInputStream = CC("@mozilla.org/binaryinputstream;1", |
michael@0 | 3 | "nsIBinaryInputStream", |
michael@0 | 4 | "setInputStream"); |
michael@0 | 5 | |
michael@0 | 6 | function setReq(req) { |
michael@0 | 7 | setObjectState("content/base/test/progressserver", req); |
michael@0 | 8 | } |
michael@0 | 9 | |
michael@0 | 10 | function getReq() { |
michael@0 | 11 | var req; |
michael@0 | 12 | getObjectState("content/base/test/progressserver", function(v) { |
michael@0 | 13 | req = v; |
michael@0 | 14 | }); |
michael@0 | 15 | return req; |
michael@0 | 16 | } |
michael@0 | 17 | |
michael@0 | 18 | function handleRequest(request, response) |
michael@0 | 19 | { |
michael@0 | 20 | var pairs = request.queryString.split('&'); |
michael@0 | 21 | var command = pairs.shift(); |
michael@0 | 22 | dump("received '" + command + "' command\n"); |
michael@0 | 23 | |
michael@0 | 24 | var bodyStream = new BinaryInputStream(request.bodyInputStream); |
michael@0 | 25 | var body = ""; |
michael@0 | 26 | var bodyAvail; |
michael@0 | 27 | while ((bodyAvail = bodyStream.available()) > 0) |
michael@0 | 28 | body += String.fromCharCode.apply(null, bodyStream.readByteArray(bodyAvail)); |
michael@0 | 29 | |
michael@0 | 30 | if (command == "open") { |
michael@0 | 31 | response.processAsync(); |
michael@0 | 32 | setReq(response); |
michael@0 | 33 | |
michael@0 | 34 | response.setHeader("Cache-Control", "no-cache", false); |
michael@0 | 35 | pairs.forEach(function (val) { |
michael@0 | 36 | var [name, value] = val.split('='); |
michael@0 | 37 | response.setHeader(name, unescape(value), false); |
michael@0 | 38 | }); |
michael@0 | 39 | response.write(body); |
michael@0 | 40 | return; |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | if (command == "send") { |
michael@0 | 44 | getReq().write(body); |
michael@0 | 45 | } |
michael@0 | 46 | else if (command == "close") { |
michael@0 | 47 | getReq().finish(); |
michael@0 | 48 | setReq(null); |
michael@0 | 49 | } |
michael@0 | 50 | response.setHeader("Content-Type", "text/plain"); |
michael@0 | 51 | response.write("ok"); |
michael@0 | 52 | } |