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/. */
6 // Test whether the connection limit is honored when http2 proxy is used.
9 // 1. Create 30 http requests.
10 // 2. Check if the count of all sockets created by proxy is less than 6.
14 /* import-globals-from head_cache.js */
15 /* import-globals-from head_cookies.js */
16 /* import-globals-from head_channels.js */
17 /* import-globals-from head_servers.js */
19 function makeChan(uri
) {
20 let chan
= NetUtil
.newChannel({
22 loadUsingSystemPrincipal
: true,
23 }).QueryInterface(Ci
.nsIHttpChannel
);
24 chan
.loadFlags
= Ci
.nsIChannel
.LOAD_INITIAL_DOCUMENT_URI
;
28 add_task(async
function test_connection_limit() {
29 let certdb
= Cc
["@mozilla.org/security/x509certdb;1"].getService(
32 addCertFromFile(certdb
, "http2-ca.pem", "CTu,u,u");
33 addCertFromFile(certdb
, "proxy-ca.pem", "CTu,u,u");
35 let proxy
= new NodeHTTP2ProxyServer();
37 registerCleanupFunction(async () => {
41 const maxConnections
= 6;
42 Services
.prefs
.setIntPref(
43 "network.http.max-persistent-connections-per-server",
46 registerCleanupFunction(async () => {
47 Services
.prefs
.clearUserPref(
48 "network.http.max-persistent-connections-per-server"
52 await
with_node_servers([NodeHTTP2Server
], async server
=> {
53 await server
.registerPathHandler("/test", (req
, resp
) => {
59 for (let i
= 0; i
< 30; ++i
) {
60 let chan
= makeChan(`${server.origin()}/test`);
62 new Promise(resolve
=> {
64 new ChannelListener(resolve
, null, CL_ALLOW_UNKNOWN_CL
)
69 await Promise
.all(promises
);
70 let count
= await proxy
.socketCount(server
.port());
74 "socket count should be less than maxConnections"