tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

sjs_sorting-test-server.sjs (1060B)


      1 /* Any copyright is dedicated to the Public Domain.
      2    http://creativecommons.org/publicdomain/zero/1.0/ */
      3 "use strict";
      4 
      5 function handleRequest(request, response) {
      6   response.processAsync();
      7 
      8   const params = request.queryString.split("&");
      9   const index = params.filter(s => s.includes("index="))[0].split("=")[1];
     10 
     11   let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
     12   timer.initWithCallback(
     13     () => {
     14       // to avoid garbage collection
     15       timer = null;
     16       response.setStatusLine(
     17         request.httpVersion,
     18         index == 1 ? 101 : index * 100,
     19         "Meh"
     20       );
     21 
     22       response.setHeader(
     23         "Cache-Control",
     24         "no-cache, no-store, must-revalidate"
     25       );
     26       response.setHeader("Pragma", "no-cache");
     27       response.setHeader("Expires", "0");
     28 
     29       response.setHeader("Content-Type", "text/" + index, false);
     30       response.write(new Array(index * 10).join(index)); // + 0.01 KB
     31       response.finish();
     32     },
     33     10,
     34     Ci.nsITimer.TYPE_ONE_SHOT
     35   ); // Make sure this request takes a few ms.
     36 }