1const CC = Components.Constructor; 2 3const BinaryInputStream = CC("@mozilla.org/binaryinputstream;1", 4 "nsIBinaryInputStream", 5 "setInputStream"); 6const BinaryOutputStream = CC("@mozilla.org/binaryoutputstream;1", 7 "nsIBinaryOutputStream", 8 "setOutputStream"); 9const Timer = CC("@mozilla.org/timer;1", 10 "nsITimer", 11 "initWithCallback"); 12 13function handleRequest(request, response) { 14 var bodyStream = new BinaryInputStream(request.bodyInputStream); 15 var bodyBytes = []; 16 while ((bodyAvail = bodyStream.available()) > 0) 17 Array.prototype.push.apply(bodyBytes, bodyStream.readByteArray(bodyAvail)); 18 19 var bos = new BinaryOutputStream(response.bodyOutputStream); 20 21 response.processAsync(); 22 23 var part = bodyBytes.splice(0, 256); 24 bos.writeByteArray(part); 25 26 response.timer1 = new Timer(function(timer) { 27 bos.writeByteArray(bodyBytes); 28 }, 1000, Components.interfaces.nsITimer.TYPE_ONE_SHOT); 29 30 response.timer2 = new Timer(function(timer) { 31 response.finish(); 32 }, 2000, Components.interfaces.nsITimer.TYPE_ONE_SHOT); 33} 34