1763581-1.sjs (1764B)
1 2 function getFileStream(filename) 3 { 4 // Get the location of this sjs file, and then use that to figure out where 5 // to find where our other files are. 6 var self = Components.classes["@mozilla.org/file/local;1"] 7 .createInstance(Components.interfaces.nsIFile); 8 self.initWithPath(getState("__LOCATION__")); 9 var file = self.parent; 10 file.append(filename); 11 12 var fileStream = Components.classes['@mozilla.org/network/file-input-stream;1'] 13 .createInstance(Components.interfaces.nsIFileInputStream); 14 fileStream.init(file, 1, 0, false); 15 16 return fileStream; 17 } 18 19 // stolen from file_blocked_script.sjs 20 function setGlobalState(data, key) { 21 x = { 22 data, 23 QueryInterface: ChromeUtils.generateQI([]), 24 }; 25 x.wrappedJSObject = x; 26 setObjectState(key, x); 27 } 28 29 function getGlobalState(key) { 30 var data; 31 getObjectState(key, function(x) { 32 data = x && x.wrappedJSObject.data; 33 }); 34 return data; 35 } 36 37 const DELAY_MS = 100; 38 let gTimer; 39 40 function handleRequest(request, response) { 41 let count = getGlobalState("count"); 42 if (count == null) { 43 count = 0; 44 } 45 46 if (count > 0) { 47 response.processAsync(); 48 49 gTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); 50 gTimer.init( 51 () => { 52 response.setStatusLine(request.httpVersion, 304, "Not Modified"); 53 response.finish(); 54 }, 55 DELAY_MS, 56 Ci.nsITimer.TYPE_ONE_SHOT 57 ); 58 59 return; 60 } 61 62 response.setStatusLine(request.httpVersion, 200, "OK"); 63 response.setHeader("Content-Type", "image/gif", false); 64 65 var inputStream = getFileStream("1763581-1.gif"); 66 response.bodyOutputStream.writeFrom(inputStream, inputStream.available()); 67 inputStream.close(); 68 69 count++; 70 setGlobalState(count, "count"); 71 }