1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /* import-globals-from head_cache.js */
8 /* import-globals-from head_cookies.js */
9 /* import-globals-from head_channels.js */
10 /* import-globals-from head_servers.js */
13 const CONTENT = "x".repeat(SIZE);
15 add_task(async function test_slow_upload() {
16 let certdb = Cc["@mozilla.org/security/x509certdb;1"].getService(
19 addCertFromFile(certdb, "http2-ca.pem", "CTu,u,u");
20 addCertFromFile(certdb, "proxy-ca.pem", "CTu,u,u");
27 for (let p of proxies) {
30 registerCleanupFunction(async () => {
34 await with_node_servers(
35 [NodeHTTPServer, NodeHTTPSServer, NodeHTTP2Server],
37 info(`Testing ${p.name} with ${server.constructor.name}`);
39 `global.server_name = "${server.constructor.name}";`
41 await server.registerPathHandler("/test", (req, resp) => {
43 req.on("data", data => {
44 global.data_count = (global.data_count || 0) + 1;
54 "@mozilla.org/io/string-input-stream;1"
55 ].createInstance(Ci.nsIStringInputStream);
56 sstream.data = CONTENT;
59 "@mozilla.org/network/mime-input-stream;1"
60 ].createInstance(Ci.nsIMIMEInputStream);
61 mime.addHeader("Content-Type", "multipart/form-data; boundary=zzzzz");
62 mime.setData(sstream);
64 let tq = Cc["@mozilla.org/network/throttlequeue;1"].createInstance(
65 Ci.nsIInputChannelThrottleQueue
67 // Make sure the request takes more than one read.
68 tq.init(100 + SIZE / 2, 100 + SIZE / 2);
70 let chan = NetUtil.newChannel({
71 uri: `${server.origin()}/test`,
72 loadUsingSystemPrincipal: true,
73 }).QueryInterface(Ci.nsIHttpChannel);
75 let tic = chan.QueryInterface(Ci.nsIThrottledInputChannel);
76 tic.throttleQueue = tq;
79 .QueryInterface(Ci.nsIUploadChannel)
80 .setUploadStream(mime, "", mime.available());
81 chan.requestMethod = "POST";
83 let { req, buff } = await new Promise(resolve => {
86 (req1, buff1) => resolve({ req: req1, buff: buff1 }),
92 equal(req.status, Cr.NS_OK);
93 equal(req.QueryInterface(Ci.nsIHttpChannel).responseStatus, 200);
94 ok(buff == CONTENT, "Content must match");
95 ok(!!req.QueryInterface(Ci.nsIProxiedChannel).proxyInfo);
97 await server.execute(`global.data_count`),
99 "Content should have been streamed to the server in several chunks"