tor-browser

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

html_params-test-page.html (2667B)


      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  </head>
     13 
     14  <body>
     15    <p>Request params type test</p>
     16 
     17    <script type="text/javascript">
     18      /* exported performRequests */
     19      "use strict";
     20 
     21      async function get(address, query) {
     22        return new Promise(resolve => {
     23          const xhr = new XMLHttpRequest();
     24          xhr.open("GET", address + query, true);
     25          xhr.onreadystatechange = function() {
     26            if (this.readyState == this.DONE) {
     27              resolve();
     28            }
     29          };
     30          xhr.send();
     31        });
     32      }
     33 
     34      async function request(address, query, contentType, requestBody, method) {
     35        return new Promise(resolve => {
     36          const xhr = new XMLHttpRequest();
     37          xhr.open(method, address + query, true);
     38          xhr.setRequestHeader("content-type", contentType);
     39          xhr.onreadystatechange = function() {
     40            if (this.readyState == this.DONE) {
     41              resolve();
     42            }
     43          };
     44          xhr.send(requestBody);
     45        });
     46      }
     47 
     48      async function post(address, query, contentType, postBody) {
     49        return request(address, query, contentType, postBody, "POST");
     50      }
     51 
     52      async function patch(address, query, contentType, patchBody) {
     53        return request(address, query, contentType, patchBody, "PATCH");
     54      }
     55 
     56      async function put(address, query, contentType, putBody) {
     57        return request(address, query, contentType, putBody, "PUT");
     58      }
     59 
     60      async function performRequests() {
     61        const urlencoded = "application/x-www-form-urlencoded";
     62        await post("baz", "?a", urlencoded, '{ "foo": "bar" }');
     63        await post("baz", "?a=b", urlencoded, '{ "foo": "bar" }');
     64        await post("baz", "?a=b", urlencoded, "?foo=bar=123=xyz");
     65        await post("baz", "?a", undefined, '{ "foo": "bar" }');
     66        await post("baz", "?a=b", undefined, '{ "foo": "bar" }');
     67        await post("baz", "?a=b", undefined, "?foo=bar");
     68        await get("baz", "");
     69        await patch("baz", "?a=b", urlencoded, '{ "foo": "bar" }');
     70        await put("baz", "?a=b", urlencoded, '{ "foo": "bar" }');
     71        await get("baz", "?species=in=(52,60)");
     72        await get("baz", "?a=&a=b");
     73        await get("baz", "?a=b&a=c&d=1");
     74      }
     75    </script>
     76  </body>
     77 
     78 </html>