2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2010-03-22 04:52:35 +03:00
|
|
|
|
2012-08-14 18:06:17 +04:00
|
|
|
Components.utils.import("resource://testing-common/httpd.js");
|
2010-03-22 04:52:35 +03:00
|
|
|
|
2013-07-16 04:13:37 +04:00
|
|
|
var server = new HttpServer();
|
|
|
|
server.start(-1);
|
2010-03-22 04:52:35 +03:00
|
|
|
|
2013-07-16 04:13:37 +04:00
|
|
|
const SERVER_PORT = server.identity.primaryPort;
|
2010-03-22 04:52:35 +03:00
|
|
|
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");
|
|
|
|
}
|
2011-07-26 02:08:44 +04:00
|
|
|
try {
|
|
|
|
metadata.getHeader("X-Unwanted-Header");
|
|
|
|
do_throw("Unwanted header present after redirect");
|
|
|
|
} catch (x) {
|
|
|
|
}
|
2010-03-22 04:52:35 +03:00
|
|
|
response.setStatusLine(metadata.httpVersion, 200, "OK");
|
|
|
|
response.setHeader("Content-Type", "text/plain");
|
|
|
|
response.write("");
|
|
|
|
}
|
|
|
|
|
|
|
|
function run_test() {
|
|
|
|
server.registerPathHandler(redirectPath, redirectHandler);
|
|
|
|
server.registerPathHandler(headerCheckPath, headerCheckHandler);
|
|
|
|
|
|
|
|
do_test_pending();
|
|
|
|
var request = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"]
|
|
|
|
.createInstance(Components.interfaces.nsIXMLHttpRequest);
|
2011-07-26 02:08:44 +04:00
|
|
|
request.open("GET", redirectURL, true);
|
2010-03-22 04:52:35 +03:00
|
|
|
request.setRequestHeader("X-Custom-Header", "present");
|
2011-09-29 20:06:36 +04:00
|
|
|
request.addEventListener("readystatechange", function() {
|
2011-07-26 02:08:44 +04:00
|
|
|
if (request.readyState == 4) {
|
|
|
|
do_check_eq(request.status, 200);
|
|
|
|
server.stop(do_test_finished);
|
|
|
|
}
|
2017-01-17 13:50:25 +03:00
|
|
|
});
|
2011-07-26 02:08:44 +04:00
|
|
|
request.send();
|
|
|
|
try {
|
|
|
|
request.setRequestHeader("X-Unwanted-Header", "present");
|
|
|
|
do_throw("Shouldn't be able to set a header after send");
|
|
|
|
} catch (x) {
|
|
|
|
}
|
2010-03-22 04:52:35 +03:00
|
|
|
}
|