file_slow_download.sjs (783B)
1 "use strict"; 2 let timer; 3 4 // Send a part of the file then wait for 3 second before sending the rest. 5 // If download isn't exempt from background timer of https-only/-first then the download 6 // gets cancelled before it completed. 7 const DELAY_MS = 3500; 8 function handleRequest(request, response) { 9 response.processAsync(); 10 timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); 11 response.setHeader("Cache-Control", "no-cache", false); 12 response.setHeader( 13 "Content-Disposition", 14 "attachment; filename=large-dummy-file.txt" 15 ); 16 response.setHeader("Content-Type", "text/plain"); 17 response.write("Begin the file"); 18 timer.init( 19 () => { 20 response.write("End of file"); 21 response.finish(); 22 }, 23 DELAY_MS, 24 Ci.nsITimer.TYPE_ONE_SHOT 25 ); 26 }