tor-browser

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

response-null-body.any.js (1509B)


      1 // META: global=window,worker
      2 // META: script=../resources/utils.js
      3 
      4 const nullBodyStatus = [204, 205, 304];
      5 const methods = ["GET", "POST", "OPTIONS"];
      6 
      7 for (const status of nullBodyStatus) {
      8  for (const method of methods) {
      9    promise_test(
     10      async () => {
     11        const url =
     12          `${RESOURCES_DIR}status.py?code=${status}&content=hello-world`;
     13        const resp = await fetch(url, { method });
     14        assert_equals(resp.status, status);
     15        assert_equals(resp.body, null, "the body should be null");
     16        const text = await resp.text();
     17        assert_equals(text, "", "null bodies result in empty text");
     18      },
     19      `Response.body is null for responses with status=${status} (method=${method})`,
     20    );
     21  }
     22 }
     23 
     24 promise_test(async () => {
     25  const url = `${RESOURCES_DIR}status.py?code=200&content=hello-world`;
     26  const resp = await fetch(url, { method: "HEAD" });
     27  assert_equals(resp.status, 200);
     28  assert_equals(resp.body, null, "the body should be null");
     29  const text = await resp.text();
     30  assert_equals(text, "", "null bodies result in empty text");
     31 }, `Response.body is null for responses with method=HEAD`);
     32 
     33 promise_test(async (t) => {
     34  const integrity = "sha384-UT6f7WCFp32YJnp1is4l/ZYnOeQKpE8xjmdkLOwZ3nIP+tmT2aMRFQGJomjVf5cE";
     35  const url = `${RESOURCES_DIR}status.py?code=204&content=hello-world`;
     36  const promise = fetch(url, { method: "GET", integrity });
     37  promise_rejects_js(t, TypeError, promise);
     38 }, "Null body status with subresource integrity should abort");