tor-browser

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

test_http_headers.js (1649B)


      1 "use strict";
      2 
      3 function check_request_header(chan, name, value) {
      4  var chanValue;
      5  try {
      6    chanValue = chan.getRequestHeader(name);
      7  } catch (e) {
      8    do_throw("Expected to find header '" + name + "' but didn't find it");
      9  }
     10  Assert.equal(chanValue, value);
     11 }
     12 
     13 function run_test() {
     14  var chan = NetUtil.newChannel({
     15    uri: "http://www.mozilla.org/",
     16    loadUsingSystemPrincipal: true,
     17  }).QueryInterface(Ci.nsIHttpChannel);
     18 
     19  check_request_header(chan, "host", "www.mozilla.org");
     20  check_request_header(chan, "Host", "www.mozilla.org");
     21 
     22  chan.setRequestHeader("foopy", "bar", false);
     23  check_request_header(chan, "foopy", "bar");
     24 
     25  chan.setRequestHeader("foopy", "baz", true);
     26  check_request_header(chan, "foopy", "bar, baz");
     27 
     28  for (let i = 0; i < 100; ++i) {
     29    chan.setRequestHeader("foopy" + i, i, false);
     30  }
     31 
     32  for (let i = 0; i < 100; ++i) {
     33    check_request_header(chan, "foopy" + i, i);
     34  }
     35 
     36  var x = false;
     37  try {
     38    chan.setRequestHeader("foo:py", "baz", false);
     39  } catch (e) {
     40    x = true;
     41  }
     42  if (!x) {
     43    do_throw("header with colon not rejected");
     44  }
     45 
     46  x = false;
     47  try {
     48    chan.setRequestHeader("foopy", "b\naz", false);
     49  } catch (e) {
     50    x = true;
     51  }
     52  if (!x) {
     53    do_throw("header value with newline not rejected");
     54  }
     55 
     56  x = false;
     57  try {
     58    chan.setRequestHeader("foopy\u0080", "baz", false);
     59  } catch (e) {
     60    x = true;
     61  }
     62  if (!x) {
     63    do_throw("header name with non-ASCII not rejected");
     64  }
     65 
     66  x = false;
     67  try {
     68    chan.setRequestHeader("foopy", "b\u0000az", false);
     69  } catch (e) {
     70    x = true;
     71  }
     72  if (!x) {
     73    do_throw("header value with null-byte not rejected");
     74  }
     75 }