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