Thu, 15 Jan 2015 15:55:04 +0100
Back out 97036ab72558 which inappropriately compared turds to third parties.
michael@0 | 1 | function check_request_header(chan, name, value) { |
michael@0 | 2 | var chanValue; |
michael@0 | 3 | try { |
michael@0 | 4 | chanValue = chan.getRequestHeader(name); |
michael@0 | 5 | } catch (e) { |
michael@0 | 6 | do_throw("Expected to find header '" + name + "' but didn't find it"); |
michael@0 | 7 | } |
michael@0 | 8 | do_check_eq(chanValue, value); |
michael@0 | 9 | } |
michael@0 | 10 | |
michael@0 | 11 | function run_test() { |
michael@0 | 12 | var ios = Components.classes["@mozilla.org/network/io-service;1"] |
michael@0 | 13 | .getService(Components.interfaces.nsIIOService); |
michael@0 | 14 | var chan = ios.newChannel("http://www.mozilla.org/", null, null) |
michael@0 | 15 | .QueryInterface(Components.interfaces.nsIHttpChannel); |
michael@0 | 16 | |
michael@0 | 17 | check_request_header(chan, "host", "www.mozilla.org"); |
michael@0 | 18 | check_request_header(chan, "Host", "www.mozilla.org"); |
michael@0 | 19 | |
michael@0 | 20 | chan.setRequestHeader("foopy", "bar", false); |
michael@0 | 21 | check_request_header(chan, "foopy", "bar"); |
michael@0 | 22 | |
michael@0 | 23 | chan.setRequestHeader("foopy", "baz", true); |
michael@0 | 24 | check_request_header(chan, "foopy", "bar, baz"); |
michael@0 | 25 | |
michael@0 | 26 | for (var i = 0; i < 100; ++i) |
michael@0 | 27 | chan.setRequestHeader("foopy" + i, i, false); |
michael@0 | 28 | |
michael@0 | 29 | for (var i = 0; i < 100; ++i) |
michael@0 | 30 | check_request_header(chan, "foopy" + i, i); |
michael@0 | 31 | |
michael@0 | 32 | var x = false; |
michael@0 | 33 | try { |
michael@0 | 34 | chan.setRequestHeader("foo:py", "baz", false); |
michael@0 | 35 | } catch (e) { |
michael@0 | 36 | x = true; |
michael@0 | 37 | } |
michael@0 | 38 | if (!x) |
michael@0 | 39 | do_throw("header with colon not rejected"); |
michael@0 | 40 | |
michael@0 | 41 | x = false; |
michael@0 | 42 | try { |
michael@0 | 43 | chan.setRequestHeader("foopy", "b\naz", false); |
michael@0 | 44 | } catch (e) { |
michael@0 | 45 | x = true; |
michael@0 | 46 | } |
michael@0 | 47 | if (!x) |
michael@0 | 48 | do_throw("header value with newline not rejected"); |
michael@0 | 49 | |
michael@0 | 50 | x = false; |
michael@0 | 51 | try { |
michael@0 | 52 | chan.setRequestHeader("foopy\u0080", "baz", false); |
michael@0 | 53 | } catch (e) { |
michael@0 | 54 | x = true; |
michael@0 | 55 | } |
michael@0 | 56 | if (!x) |
michael@0 | 57 | do_throw("header name with non-ASCII not rejected"); |
michael@0 | 58 | |
michael@0 | 59 | x = false; |
michael@0 | 60 | try { |
michael@0 | 61 | chan.setRequestHeader("foopy", "b\u0000az", false); |
michael@0 | 62 | } catch (e) { |
michael@0 | 63 | x = true; |
michael@0 | 64 | } |
michael@0 | 65 | if (!x) |
michael@0 | 66 | do_throw("header value with null-byte not rejected"); |
michael@0 | 67 | } |