3 const { HttpServer } = ChromeUtils.importESModule(
4 "resource://testing-common/httpd.sys.mjs"
7 ChromeUtils.defineLazyGetter(this, "URL", function () {
8 return "http://localhost:" + httpserver.identity.primaryPort;
11 var httpserver = new HttpServer();
12 var testpath = "/421";
13 var httpbody = "0123456789";
21 function setup_test() {
22 httpserver.registerPathHandler(testpath, serverHandler);
25 channel = setupChannel(testpath);
27 channel.asyncOpen(new ChannelListener(checkRequestResponse, channel));
30 function setupChannel(path) {
31 var chan = NetUtil.newChannel({
33 loadUsingSystemPrincipal: true,
35 chan.QueryInterface(Ci.nsIHttpChannel);
36 chan.requestMethod = "GET";
42 function serverHandler(metadata, response) {
43 response.setHeader("Content-Type", "text/plain", false);
46 response.setStatusLine("1.1", 421, "Not Authoritative " + iters);
48 response.setStatusLine("1.1", 200, "OK");
52 response.bodyOutputStream.write(httpbody, httpbody.length);
55 function checkRequestResponse(request, data) {
56 Assert.equal(channel.responseStatus, 200);
57 Assert.equal(channel.responseStatusText, "OK");
58 Assert.ok(channel.requestSucceeded);
60 Assert.equal(channel.contentType, "text/plain");
61 Assert.equal(channel.contentLength, httpbody.length);
62 Assert.equal(data, httpbody);
64 httpserver.stop(do_test_finished);