sendimagenevercomplete.sjs (1074B)
1 function getFileStream(filename) { 2 // Get the location of this sjs file, and then use that to figure out where 3 // to find where our other files are. 4 var self = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile); 5 self.initWithPath(getState("__LOCATION__")); 6 var file = self.parent; 7 file.append(filename); 8 9 var fileStream = Cc[ 10 "@mozilla.org/network/file-input-stream;1" 11 ].createInstance(Ci.nsIFileInputStream); 12 fileStream.init(file, 1, 0, false); 13 14 return fileStream; 15 } 16 17 function handleRequest(request, response) { 18 // partial.png is a truncated png 19 // by calling processAsync and not calling finish we send the truncated png 20 // in it's entirety but the webserver doesn't close to connection to indicate 21 // that all data has been delivered. 22 response.processAsync(); 23 response.setStatusLine(request.httpVersion, 200, "OK"); 24 response.setHeader("Content-Type", "image/png", false); 25 26 var inputStream = getFileStream("partial.png"); 27 response.bodyOutputStream.writeFrom(inputStream, inputStream.available()); 28 inputStream.close(); 29 }