1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/base/test/progressserver.sjs Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,52 @@ 1.4 +const CC = Components.Constructor; 1.5 +const BinaryInputStream = CC("@mozilla.org/binaryinputstream;1", 1.6 + "nsIBinaryInputStream", 1.7 + "setInputStream"); 1.8 + 1.9 +function setReq(req) { 1.10 + setObjectState("content/base/test/progressserver", req); 1.11 +} 1.12 + 1.13 +function getReq() { 1.14 + var req; 1.15 + getObjectState("content/base/test/progressserver", function(v) { 1.16 + req = v; 1.17 + }); 1.18 + return req; 1.19 +} 1.20 + 1.21 +function handleRequest(request, response) 1.22 +{ 1.23 + var pairs = request.queryString.split('&'); 1.24 + var command = pairs.shift(); 1.25 + dump("received '" + command + "' command\n"); 1.26 + 1.27 + var bodyStream = new BinaryInputStream(request.bodyInputStream); 1.28 + var body = ""; 1.29 + var bodyAvail; 1.30 + while ((bodyAvail = bodyStream.available()) > 0) 1.31 + body += String.fromCharCode.apply(null, bodyStream.readByteArray(bodyAvail)); 1.32 + 1.33 + if (command == "open") { 1.34 + response.processAsync(); 1.35 + setReq(response); 1.36 + 1.37 + response.setHeader("Cache-Control", "no-cache", false); 1.38 + pairs.forEach(function (val) { 1.39 + var [name, value] = val.split('='); 1.40 + response.setHeader(name, unescape(value), false); 1.41 + }); 1.42 + response.write(body); 1.43 + return; 1.44 + } 1.45 + 1.46 + if (command == "send") { 1.47 + getReq().write(body); 1.48 + } 1.49 + else if (command == "close") { 1.50 + getReq().finish(); 1.51 + setReq(null); 1.52 + } 1.53 + response.setHeader("Content-Type", "text/plain"); 1.54 + response.write("ok"); 1.55 +}