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 ChromeUtils.defineLazyGetter(this, "uri", function () {
12 return URL + "/redirect";
15 ChromeUtils.defineLazyGetter(this, "noRedirectURI", function () {
16 return URL + "/content";
19 var httpserver = null;
21 function make_channel(url) {
22 return NetUtil.newChannel({ uri: url, loadUsingSystemPrincipal: true });
25 const requestBody = "request body";
27 function redirectHandler(metadata, response) {
28 response.setStatusLine(metadata.httpVersion, 307, "Moved Temporarily");
29 response.setHeader("Location", noRedirectURI, false);
32 function contentHandler(metadata, response) {
33 response.setHeader("Content-Type", "text/plain");
34 response.bodyOutputStream.writeFrom(
35 metadata.bodyInputStream,
36 metadata.bodyInputStream.available()
40 function noRedirectStreamObserver(request, buffer) {
41 Assert.equal(buffer, requestBody);
42 var chan = make_channel(uri);
43 var uploadStream = Cc["@mozilla.org/io/string-input-stream;1"].createInstance(
44 Ci.nsIStringInputStream
46 uploadStream.setData(requestBody, requestBody.length);
48 .QueryInterface(Ci.nsIUploadChannel)
49 .setUploadStream(uploadStream, "text/plain", -1);
50 chan.asyncOpen(new ChannelListener(noHeaderStreamObserver, null));
53 function noHeaderStreamObserver(request, buffer) {
54 Assert.equal(buffer, requestBody);
55 var chan = make_channel(uri);
56 var uploadStream = Cc["@mozilla.org/io/string-input-stream;1"].createInstance(
57 Ci.nsIStringInputStream
60 "Content-Type: text/plain\r\n" +
65 uploadStream.setData(streamBody, streamBody.length);
67 .QueryInterface(Ci.nsIUploadChannel)
68 .setUploadStream(uploadStream, "", -1);
69 chan.asyncOpen(new ChannelListener(headerStreamObserver, null));
72 function headerStreamObserver(request, buffer) {
73 Assert.equal(buffer, requestBody);
74 httpserver.stop(do_test_finished);
78 httpserver = new HttpServer();
79 httpserver.registerPathHandler("/redirect", redirectHandler);
80 httpserver.registerPathHandler("/content", contentHandler);
83 Services.prefs.setBoolPref("network.http.prompt-temp-redirect", false);
85 var chan = make_channel(noRedirectURI);
86 var uploadStream = Cc["@mozilla.org/io/string-input-stream;1"].createInstance(
87 Ci.nsIStringInputStream
89 uploadStream.setData(requestBody, requestBody.length);
91 .QueryInterface(Ci.nsIUploadChannel)
92 .setUploadStream(uploadStream, "text/plain", -1);
93 chan.asyncOpen(new ChannelListener(noRedirectStreamObserver, null));