tor-browser

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

bug1309630.sjs (2096B)


      1 function handleRequest(request, response) {
      2   const XSLT = `<?xml version="1.0"?>
      3     <?xml-stylesheet type="text/xsl" href="#bug"?>
      4     <xsl:stylesheet id="bug" version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      5       <xsl:template name="f" match="/">
      6         <xsl:param name="n" select="0" />
      7         <xsl:apply-templates select="document(concat('${request.path}?', $n))/xsl:stylesheet/xsl:template[@name='f']">
      8           <xsl:with-param name="n" select="$n + 1"/>
      9         </xsl:apply-templates>
     10         <xsl:call-template name="f">
     11           <xsl:with-param name="n" select="$n + 1"/>
     12         </xsl:call-template>
     13       </xsl:template>
     14     </xsl:stylesheet>`;
     15 
     16   // reset_counter sets the counter to -1.
     17   if (request.queryString === "reset_counter") {
     18     setState("base", "-1");
     19     response.write("");
     20     return;
     21   }
     22 
     23   // record_counter makes us store the current value of the counter.
     24   if (request.queryString === "record_counter") {
     25     setState("base", getState("counter"));
     26     response.write("");
     27     return;
     28   }
     29 
     30   // get_counter_change returns the difference between the current
     31   // value of the counter and the value it had when the script was
     32   // loaded with the record_counter query string.
     33   if (request.queryString === "get_counter_change") {
     34     response.write(
     35       String(Number(getState("counter")) - Number(getState("base")))
     36     );
     37     return;
     38   }
     39 
     40   // The XSLT code calls the document() function with a URL pointing to
     41   // this script, with the query string set to a counter starting from 0
     42   // and incremementing with every call of the document() function.
     43   // The first load will happen either from the xml-stylesheet PI, or
     44   // with fetch(), to parse a document to pass to
     45   // XSLTProcessor.importStylesheet. In that case the query string will
     46   // be empty, and we don't change the counter value, we only care about
     47   // the loads through the document() function.
     48   if (request.queryString) {
     49     setState("counter", request.queryString);
     50   }
     51 
     52   response.setHeader("Content-Type", "text/xml; charset=utf-8", false);
     53   response.write(XSLT);
     54 }