forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_bug553888.js
61 lines (54 loc) · 1.97 KB
/
test_bug553888.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
do_load_httpd_js();
var server = null;
const SERVER_PORT = 4444;
const HTTP_BASE = "http://localhost:" + SERVER_PORT;
const redirectPath = "/redirect";
const headerCheckPath = "/headerCheck";
const redirectURL = HTTP_BASE + redirectPath;
const headerCheckURL = HTTP_BASE + headerCheckPath;
function redirectHandler(metadata, response) {
response.setStatusLine(metadata.httpVersion, 302, "Found");
response.setHeader("Location", headerCheckURL, false);
}
function headerCheckHandler(metadata, response) {
try {
let headerValue = metadata.getHeader("X-Custom-Header");
do_check_eq(headerValue, "present");
} catch(e) {
do_throw("No header present after redirect");
}
try {
metadata.getHeader("X-Unwanted-Header");
do_throw("Unwanted header present after redirect");
} catch (x) {
}
response.setStatusLine(metadata.httpVersion, 200, "OK");
response.setHeader("Content-Type", "text/plain");
response.write("");
}
function run_test() {
var server = new nsHttpServer();
server.registerPathHandler(redirectPath, redirectHandler);
server.registerPathHandler(headerCheckPath, headerCheckHandler);
server.start(SERVER_PORT);
do_test_pending();
var request = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"]
.createInstance(Components.interfaces.nsIXMLHttpRequest);
request.open("GET", redirectURL, true);
request.setRequestHeader("X-Custom-Header", "present");
request.addEventListener("readystatechange", function() {
if (request.readyState == 4) {
do_check_eq(request.status, 200);
server.stop(do_test_finished);
}
}, false);
request.send();
try {
request.setRequestHeader("X-Unwanted-Header", "present");
do_throw("Shouldn't be able to set a header after send");
} catch (x) {
}
}