1 // This file tests bug 250375
3 do_import_script("netwerk/test/httpserver/httpd.js");
5 function check_request_header(chan
, name
, value
) {
8 chanValue
= chan
.getRequestHeader(name
);
10 do_throw("Expected to find header '" + name
+ "' but didn't find it");
12 dump("Value for header '" + name
+ "' is '" + chanValue
+ "'\n");
13 do_check_eq(chanValue
, value
);
16 var cookieVal
= "C1=V1";
19 onStartRequest
: function test_onStartR(request
, ctx
) {
21 var chan
= request
.QueryInterface(Components
.interfaces
.nsIChannel
);
22 check_request_header(chan
, "Cookie", cookieVal
);
24 do_throw("Unexpected exception: " + e
);
27 throw Components
.results
.NS_ERROR_ABORT
;
30 onDataAvailable
: function test_ODA() {
31 throw Components
.results
.NS_ERROR_UNEXPECTED
;
34 onStopRequest
: function test_onStopR(request
, ctx
, status
) {
35 if (this._iteration
== 1)
46 var ios
= Components
.classes
["@mozilla.org/network/io-service;1"]
47 .getService(Components
.interfaces
.nsIIOService
);
48 var chan
= ios
.newChannel("http://localhost:4444/", null, null)
49 .QueryInterface(Components
.interfaces
.nsIHttpChannel
);
57 httpserv
= new nsHttpServer();
60 var chan
= makeChan();
62 chan
.setRequestHeader("Cookie", cookieVal
, false);
64 chan
.asyncOpen(listener
, null);
69 function run_test_continued() {
70 var chan
= makeChan();
72 var cookServ
= Components
.classes
["@mozilla.org/cookieService;1"]
73 .getService(Components
.interfaces
.nsICookieService
);
74 var cookie2
= "C2=V2";
75 cookServ
.setCookieString(chan
.URI
, null, cookie2
, chan
);
76 chan
.setRequestHeader("Cookie", cookieVal
, false);
78 // We expect that the setRequestHeader overrides the
79 // automatically-added one, so insert cookie2 in front
80 cookieVal
= cookie2
+ "; " + cookieVal
;
82 listener
._iteration
++;
83 chan
.asyncOpen(listener
, null);