tor-browser

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

file_downgrade_500_responses.sjs (2049B)


      1 // Custom *.sjs file specifically for the needs of Bug 1709552
      2 "use strict";
      3 
      4 const RESPONSE_SUCCESS = `
      5   <html>
      6     <body>
      7       send message, downgraded
      8     <script type="application/javascript">
      9       let scheme = document.location.protocol;
     10       window.opener.postMessage({result: 'downgraded', scheme: scheme}, '*');
     11     </script>
     12     </body>
     13   </html>`;
     14 
     15 const RESPONSE_UNEXPECTED = `
     16   <html>
     17     <body>
     18       send message, error
     19     <script type="application/javascript">
     20       let scheme = document.location.protocol;
     21       window.opener.postMessage({result: 'Error', scheme: scheme}, '*');
     22     </script>
     23     </body>
     24   </html>`;
     25 
     26 function handleRequest(request, response) {
     27   // avoid confusing cache behaviour
     28   response.setHeader("Cache-Control", "no-cache", false);
     29   response.setHeader("Content-Type", "text/html", false);
     30 
     31   let query = request.queryString;
     32   // if the scheme is not https and it is the initial request
     33   // then we rather fall through and display unexpected content
     34   if (request.scheme === "https") {
     35     if (query === "test1a") {
     36       response.setStatusLine("1.1", 501, "Not Implemented");
     37       response.write("Not Implemented\n");
     38       return;
     39     }
     40 
     41     if (query === "test2a") {
     42       response.setStatusLine("1.1", 504, "Gateway Timeout");
     43       response.write("Gateway Timeout\n");
     44       return;
     45     }
     46 
     47     if (query === "test3a") {
     48       response.setStatusLine("1.1", 521, "Web Server Is Down");
     49       response.write("Web Server Is Down\n");
     50       return;
     51     }
     52     if (query === "test4a") {
     53       response.setStatusLine("1.1", 530, "Railgun Error");
     54       response.write("Railgun Error\n");
     55       return;
     56     }
     57     if (query === "test5a") {
     58       response.setStatusLine("1.1", 560, "Unauthorized");
     59       response.write("Unauthorized\n");
     60       return;
     61     }
     62 
     63     // We should never arrive here, just in case send something unexpected
     64     response.write(RESPONSE_UNEXPECTED);
     65     return;
     66   }
     67 
     68   // We should arrive here when the redirection was downraded successful
     69   response.write(RESPONSE_SUCCESS);
     70 }