tor-browser

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

html_post-data-test-page.html (2647B)


      1 <!-- Any copyright is dedicated to the Public Domain.
      2     http://creativecommons.org/publicdomain/zero/1.0/ -->
      3 <!doctype html>
      4 
      5 <html>
      6  <head>
      7    <meta charset="utf-8"/>
      8    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
      9    <meta http-equiv="Pragma" content="no-cache" />
     10    <meta http-equiv="Expires" content="0" />
     11    <title>Network Monitor test page</title>
     12    <style>
     13      input {
     14        display: block;
     15        margin: 12px;
     16      }
     17    </style>
     18  </head>
     19 
     20  <body>
     21    <p>POST data test</p>
     22    <form enctype="multipart/form-data" method="post" name="form-name">
     23      <input type="text" name="text" placeholder="text" value="Some text..."/>
     24      <input type="email" name="email" placeholder="email"/>
     25      <input type="range" name="range" value="42"/>
     26      <input type="button" value="Post me!" onclick="window.form()">
     27    </form>
     28 
     29    <script type="text/javascript">
     30      /* exported performRequests */
     31      "use strict";
     32 
     33      function post(address, message) {
     34        return new Promise(resolve => {
     35          const xhr = new XMLHttpRequest();
     36          xhr.open("POST", address, true);
     37          xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
     38 
     39          let data = "";
     40          for (const i in message) {
     41            data += "&" + i + "=" + encodeURIComponent(message[i]);
     42          }
     43 
     44          xhr.onreadystatechange = function() {
     45            if (this.readyState == this.DONE) {
     46              resolve();
     47            }
     48          };
     49          xhr.send(data);
     50        });
     51      }
     52 
     53      function form(address, formName) {
     54        return new Promise(resolve => {
     55          const formData = new FormData(document.forms.namedItem(formName));
     56          formData.append("Custom field", "Extra data");
     57 
     58          const xhr = new XMLHttpRequest();
     59          xhr.open("POST", address, true);
     60          xhr.setRequestHeader("custom-header-xxx", "custom-value-xxx");
     61          xhr.setRequestHeader("Priority", "u=3")
     62 
     63          xhr.onreadystatechange = function() {
     64            if (this.readyState == this.DONE) {
     65              resolve();
     66            }
     67          };
     68          xhr.send(formData);
     69        });
     70      }
     71 
     72      async function performRequests() {
     73        const url = "sjs_simple-test-server.sjs";
     74        const url1 = url + "?foo=bar&baz=42&valueWithEqualSign=hijk=123=mnop&type=urlencoded";
     75        const url2 = url + "?foo=bar&baz=42&type=multipart";
     76 
     77        await post(url1, { foo: "bar", baz: 123, valueWithEqualSign: "xyz=abc=123", valueWithAmpersand: "abcd&1234" });
     78        await form(url2, "form-name");
     79      }
     80    </script>
     81  </body>
     82 
     83 </html>