tor-browser

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

file_reload_large_postdata.sjs (1109B)


      1 /* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
      2 /* vim: set sts=2 sw=2 et tw=80 ft=javascript: */
      3 "use strict";
      4 
      5 const BinaryInputStream = Components.Constructor(
      6   "@mozilla.org/binaryinputstream;1",
      7   "nsIBinaryInputStream",
      8   "setInputStream"
      9 );
     10 
     11 function readStream(inputStream) {
     12   let available = 0;
     13   let result = [];
     14   while ((available = inputStream.available()) > 0) {
     15     result.push(inputStream.readBytes(available));
     16   }
     17   return result.join("");
     18 }
     19 
     20 function handleRequest(request, response) {
     21   let rv = (() => {
     22     try {
     23       if (request.method != "POST") {
     24         return "ERROR: not a POST request";
     25       }
     26 
     27       let body = new URLSearchParams(
     28         readStream(new BinaryInputStream(request.bodyInputStream))
     29       );
     30       return body.get("payload").length;
     31     } catch (e) {
     32       return "ERROR: Exception: " + e;
     33     }
     34   })();
     35 
     36   response.setHeader("Content-Type", "text/html", false);
     37   response.setHeader("Cache-Control", "no-cache", false);
     38   response.write(`<!DOCTYPE HTML>
     39 <script>
     40 let rv = (${JSON.stringify(rv)});
     41 opener.postMessage(rv, "*");
     42 </script>
     43   `);
     44 }