let httpsOrigin;
let h3AltSvc;
let h3Route;
let h3Port;
let h3ServerPath;
let h3DBPath;
let prefs;
let tests = [
test_https_alt_svc,
test_https_alt_svc_1,
test_https_speculativeConnect_alt_svc,
testsDone,
];
let current_test = 0;
function run_next_test() { if (current_test < tests.length) {
dump("starting test number " + current_test + "\n");
tests[current_test]();
current_test++;
}
}
prefs.setBoolPref("network.http.http3.enable", true);
prefs.setCharPref("network.dns.localDomains", "foo.example.com"); // We always resolve elements of localDomains as it's hardcoded without the // following pref:
prefs.setBoolPref("network.proxy.allow_hijacking_localhost", true);
// The certificate for the http3server server is for foo.example.com and // is signed by http2-ca.pem so add that cert to the trust list as a // signing cert.
let certdb = Cc["@mozilla.org/security/x509certdb;1"].getService(
Ci.nsIX509CertDB
);
addCertFromFile(certdb, "http2-ca.pem", "CTu,u,u");
httpsOrigin = "https://foo.example.com:" + h2Port + "/";
run_next_test();
}
function createPrincipal(url) { var ssm = Services.scriptSecurityManager; try { return ssm.createContentPrincipal(Services.io.newURI(url), {});
} catch (e) { returnnull;
}
}
onStopRequest: function testOnStopRequest(request) {
let routed = "NA"; try {
routed = request.getRequestHeader("Alt-Used");
} catch (e) {}
dump("routed is " + routed + "\n");
if (routed == this.expectedRoute) {
let httpVersion = ""; try {
httpVersion = request.protocolVersion;
} catch (e) {} Assert.equal(httpVersion, this._expectedH3Version);
run_next_test();
} elseif (this._retries >= MAX_POLL_RETRIES) { Assert.ok( false,
`Alt-svc route to ${this.expectedRoute} was not established after ${MAX_POLL_RETRIES} retries`
);
} else {
dump("poll later for alt svc mapping\n"); this._retries++;
do_test_pending();
do_timeout(1000, () => {
Services.obs.notifyObservers(null, "net:cancel-all-connections");
do_timeout(500, () => {
doTest( this.uri, this.expectedRoute, this.h3AltSvc, this._expectedH3Version, this._retries
);
});
});
}
do_test_finished();
},
};
function doTest(uri, expectedRoute, altSvc, expectedH3Version, retries = 0) {
let chan = makeChan(uri);
let listener = new WaitForHttp3Listener(expectedH3Version, retries);
listener.uri = uri;
listener.expectedRoute = expectedRoute;
listener.h3AltSvc = altSvc;
chan.setRequestHeader("x-altsvc", altSvc, false);
chan.asyncOpen(listener);
}
// Test Alt-Svc for http3. // H2 server returns alt-svc=h2=foo2.example.com:8000,h3=:h3port function test_https_alt_svc() {
dump("test_https_alt_svc()\n");
do_test_pending();
let server = new HTTP3Server();
server
.start(h3ServerPath, h3DBPath)
.then(() => {
h3Port = server.port();
setupAltSvc();
doTest(httpsOrigin + "http3-test2", h3Route, h3AltSvc, "h3");
})
.catch(e => { Assert.ok(false, `HTTP3Server.start failed: ${e}`);
do_test_finished();
});
}
// Test if we use the latest version of HTTP/3. // H2 server returns alt-svc=h3=:h3port,h3=:h3port function test_https_alt_svc_1() {
dump("test_https_alt_svc_1()\n");
Services.obs.notifyObservers(null, "last-pb-context-exited");
Services.obs.notifyObservers(null, "net:cancel-all-connections");
do_test_pending();
let server = new HTTP3Server();
server
.start(h3ServerPath, h3DBPath)
.then(() => {
h3Port = server.port();
setupAltSvc();
doTest(httpsOrigin + "http3-test3", h3Route, h3AltSvc, "h3");
})
.catch(e => { Assert.ok(false, `HTTP3Server.start failed: ${e}`);
do_test_finished();
});
}
function test_https_speculativeConnect_alt_svc() {
dump("test_https_speculativeConnect_alt_svc()\n");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.