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