tor-browser

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

send-conditional-cors.htm (1429B)


      1 <!doctype html>
      2 <title>XMLHttpRequest: send() - conditional cross-origin requests</title>
      3 <script src=/resources/testharness.js></script>
      4 <script src=/resources/testharnessreport.js></script>
      5 <script src=/cors/support.js?pipe=sub></script>
      6 <div id=log></div>
      7 <script>
      8 function request(withCORS, desc) {
      9  async_test(t => {
     10    const client = new XMLHttpRequest,
     11          identifier = Math.random(),
     12          cors = withCORS ? "&cors=yes" : "",
     13          url = CROSSDOMAIN + "resources/conditional.py?tag=" + identifier + cors
     14    client.onload = t.step_func(() => {
     15      assert_equals(client.status, 200)
     16      assert_equals(client.statusText, "OK")
     17      assert_equals(client.responseText, "MAYBE NOT")
     18 
     19      if(withCORS) {
     20        client.onload = t.step_func_done(() => {
     21          assert_equals(client.status, 304)
     22          assert_equals(client.statusText, "SUPERCOOL")
     23          assert_equals(client.responseText, "")
     24        })
     25      } else {
     26        client.onload = null
     27        client.onerror = t.step_func_done(() => {
     28          assert_equals(client.status, 0)
     29          assert_equals(client.statusText, "")
     30        })
     31      }
     32      client.open("GET", url)
     33      client.setRequestHeader("If-None-Match", identifier)
     34      client.send()
     35    })
     36    client.open("GET", url)
     37    client.send()
     38  }, desc)
     39 }
     40 request(false, "304 without appropriate CORS header")
     41 request(true, "304 with appropriate CORS header")
     42 </script>