Bug 1931425 - Limit how often moz-label's #setStyles runs r=reusable-components-revie...
[gecko.git] / netwerk / test / unit / test_http_headers.js
blobb43cebea1fd4b975ae2532f1f19a0ee2658dc602
1 "use strict";
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");
10 Assert.equal(chanValue, value);
13 function run_test() {
14 var chan = NetUtil.newChannel({
15 uri: "http://www.mozilla.org/",
16 loadUsingSystemPrincipal: true,
17 }).QueryInterface(Ci.nsIHttpChannel);
19 check_request_header(chan, "host", "www.mozilla.org");
20 check_request_header(chan, "Host", "www.mozilla.org");
22 chan.setRequestHeader("foopy", "bar", false);
23 check_request_header(chan, "foopy", "bar");
25 chan.setRequestHeader("foopy", "baz", true);
26 check_request_header(chan, "foopy", "bar, baz");
28 for (let i = 0; i < 100; ++i) {
29 chan.setRequestHeader("foopy" + i, i, false);
32 for (let i = 0; i < 100; ++i) {
33 check_request_header(chan, "foopy" + i, i);
36 var x = false;
37 try {
38 chan.setRequestHeader("foo:py", "baz", false);
39 } catch (e) {
40 x = true;
42 if (!x) {
43 do_throw("header with colon not rejected");
46 x = false;
47 try {
48 chan.setRequestHeader("foopy", "b\naz", false);
49 } catch (e) {
50 x = true;
52 if (!x) {
53 do_throw("header value with newline not rejected");
56 x = false;
57 try {
58 chan.setRequestHeader("foopy\u0080", "baz", false);
59 } catch (e) {
60 x = true;
62 if (!x) {
63 do_throw("header name with non-ASCII not rejected");
66 x = false;
67 try {
68 chan.setRequestHeader("foopy", "b\u0000az", false);
69 } catch (e) {
70 x = true;
72 if (!x) {
73 do_throw("header value with null-byte not rejected");