content/base/test/progressserver.sjs

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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 }

mercurial