2005-08-13 15:46:11 +04:00
|
|
|
function check_request_header(chan, name, value) {
|
|
|
|
var chanValue;
|
|
|
|
try {
|
|
|
|
chanValue = chan.getRequestHeader(name);
|
|
|
|
} catch (e) {
|
|
|
|
do_throw("Expected to find header '" + name + "' but didn't find it");
|
|
|
|
}
|
|
|
|
do_check_eq(chanValue, value);
|
2005-03-31 10:22:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function run_test() {
|
|
|
|
var ios = Components.classes["@mozilla.org/network/io-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIIOService);
|
|
|
|
var chan = ios.newChannel("http://www.mozilla.org/", null, null)
|
|
|
|
.QueryInterface(Components.interfaces.nsIHttpChannel);
|
|
|
|
|
2005-08-13 15:46:11 +04:00
|
|
|
check_request_header(chan, "host", "www.mozilla.org");
|
|
|
|
check_request_header(chan, "Host", "www.mozilla.org");
|
2005-04-01 22:35:14 +04:00
|
|
|
|
2005-03-31 10:22:11 +04:00
|
|
|
chan.setRequestHeader("foopy", "bar", false);
|
2005-08-13 15:46:11 +04:00
|
|
|
check_request_header(chan, "foopy", "bar");
|
2005-03-31 10:22:11 +04:00
|
|
|
|
|
|
|
chan.setRequestHeader("foopy", "baz", true);
|
2005-08-13 15:46:11 +04:00
|
|
|
check_request_header(chan, "foopy", "bar, baz");
|
2005-03-31 10:22:11 +04:00
|
|
|
|
|
|
|
for (var i = 0; i < 100; ++i)
|
|
|
|
chan.setRequestHeader("foopy" + i, i, false);
|
|
|
|
|
|
|
|
for (var i = 0; i < 100; ++i)
|
2005-08-13 15:46:11 +04:00
|
|
|
check_request_header(chan, "foopy" + i, i);
|
2005-07-27 00:58:35 +04:00
|
|
|
|
|
|
|
var x = false;
|
|
|
|
try {
|
|
|
|
chan.setRequestHeader("foo:py", "baz", false);
|
|
|
|
} catch (e) {
|
|
|
|
x = true;
|
|
|
|
}
|
|
|
|
if (!x)
|
|
|
|
do_throw("header with colon not rejected");
|
|
|
|
|
|
|
|
x = false;
|
|
|
|
try {
|
|
|
|
chan.setRequestHeader("foopy", "b\naz", false);
|
|
|
|
} catch (e) {
|
|
|
|
x = true;
|
|
|
|
}
|
|
|
|
if (!x)
|
|
|
|
do_throw("header value with newline not rejected");
|
2005-07-27 01:35:58 +04:00
|
|
|
|
|
|
|
x = false;
|
|
|
|
try {
|
|
|
|
chan.setRequestHeader("foopy\u0080", "baz", false);
|
|
|
|
} catch (e) {
|
|
|
|
x = true;
|
|
|
|
}
|
|
|
|
if (!x)
|
|
|
|
do_throw("header name with non-ASCII not rejected");
|
2005-07-27 22:13:11 +04:00
|
|
|
|
|
|
|
x = false;
|
|
|
|
try {
|
|
|
|
chan.setRequestHeader("foopy", "b\u0000az", false);
|
|
|
|
} catch (e) {
|
|
|
|
x = true;
|
|
|
|
}
|
|
|
|
if (!x)
|
|
|
|
do_throw("header value with null-byte not rejected");
|
2005-03-31 10:22:11 +04:00
|
|
|
}
|