/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict" ;
/* import-globals-from head_cache.js */
/* import-globals-from head_cookies.js */
/* import-globals-from head_channels.js */
/* import-globals-from head_servers.js */
let endChunk2ReceivedInTime =
false ;
function makeChan(uri) {
let chan = NetUtil.newChannel({
uri,
loadUsingSystemPrincipal:
true ,
}).QueryInterface(Ci.nsIHttpChannel);
chan.loadFlags = Ci.nsIChannel.LOAD_INITIAL_DOCUMENT_URI;
return chan;
}
let channelListener =
function (closure) {
this ._closure = closure;
this ._start = Date.now();
};
channelListener.prototype = {
onStartRequest:
function testOnStartRequest() {},
onDataAvailable:
function testOnDataAvailable(request, stream, off, cnt) {
let data = read_stream(stream, cnt);
let current = Date.now();
let elapsed = current -
this ._start;
dump(
"data:" + data.slice(-
10 ) +
"\n" );
dump(
"elapsed=" + elapsed +
"\n" );
if (elapsed <
2500 && data[data.length -
1 ] ==
"E" ) {
endChunk2ReceivedInTime =
true ;
}
},
onStopRequest:
function testOnStopRequest() {
this ._closure();
},
};
add_task(async
function test_http2() {
let certdb = Cc[
"@mozilla.org/security/x509certdb;1" ].getService(
Ci.nsIX509CertDB
);
addCertFromFile(certdb,
"http2-ca.pem" ,
"CTu,u,u" );
let server =
new NodeHTTP2Server();
await server.start();
registerCleanupFunction(async () => {
await server.stop();
});
let chan = makeChan(`https:
//localhost:${server.port()}/test`);
let req = await
new Promise(resolve => {
chan.asyncOpen(
new ChannelListener(resolve,
null , CL_ALLOW_UNKNOWN_CL));
});
equal(req.status, Cr.NS_OK);
equal(req.QueryInterface(Ci.nsIHttpChannel).responseStatus,
404 );
await server.registerPathHandler(
"/test" , (req1, resp) => {
resp.writeHead(
200 , {
"content-type" :
"text/html; charset=utf-8" ,
"content-encoding" :
"br" ,
});
resp.write(
Buffer.from([
0 x8b,
0 x2a,
0 x80,
0 x3c,
0 x64,
0 x69,
0 x76,
0 x3e,
0 x73,
0 x74,
0 x61,
0 x72,
0 x74,
0 x3c,
0 x2f,
0 x64,
0 x69,
0 x76,
0 x3e,
0 x3c,
0 x64,
0 x69,
0 x76,
0 x20,
0 x73,
0 x74,
0 x79,
0 x6c,
0 x65,
0 x3d,
0 x22,
0 x74,
0 x65,
0 x78,
0 x74,
0 x2d,
0 x6f,
0 x76,
0 x65,
0 x72,
0 x66,
0 x6c,
0 x6f,
0 x77,
0 x3a,
0 x20,
0 x65,
0 x6c,
0 x6c,
0 x69,
0 x70,
0 x73,
0 x69,
0 x73,
0 x3b,
0 x6f,
0 x76,
0 x65,
0 x72,
0 x66,
0 x6c,
0 x6f,
0 x77,
0 x3a,
0 x20,
0 x68,
0 x69,
0 x64,
0 x64,
0 x65,
0 x6e,
0 x3b,
0 x64,
0 x69,
0 x72,
0 x65,
0 x63,
0 x74,
0 x69,
0 x6f,
0 x6e,
0 x3a,
0 x20,
0 x72,
0 x74,
0 x6c,
0 x3b,
0 x22,
0 x3e,
])
);
// This function is handled within the httpserver where setTimeout is
// available.
// eslint-disable-next-line mozilla/no-arbitrary-setTimeout, no-undef
setTimeout(
function () {
resp.write(
Buffer.from([
0 xfa,
0 xff,
0 x0b,
0 x00,
0 x80,
0 xaa,
0 xaa,
0 xaa,
0 xea,
0 x3f,
0 x72,
0 x59,
0 xd6,
0 x05,
0 x73,
0 x5b,
0 xb6,
0 x75,
0 xea,
0 xe6,
0 xfd,
0 xa8,
0 x54,
0 xc7,
0 x62,
0 xd8,
0 x18,
0 x86,
0 x61,
0 x18,
0 x86,
0 x63,
0 xa9,
0 x86,
0 x61,
0 x18,
0 x86,
0 xe1,
0 x63,
0 x8e,
0 x63,
0 xa9,
0 x86,
0 x61,
0 x18,
0 x86,
0 x61,
0 xd8,
0 xe0,
0 xbc,
0 x85,
0 x48,
0 x1f,
0 xa0,
0 x05,
0 xda,
0 x6f,
0 xef,
0 x02,
0 x00,
0 x00,
0 x00,
0 x01,
0 x00,
0 xaa,
0 xaa,
0 xaa,
0 xaa,
0 xff,
0 xc8,
0 x65,
0 x59,
0 x17,
0 xcc,
0 x6d,
0 xd9,
0 xd6,
0 xa9,
0 x9b,
0 xf7,
0 xff,
0 x0d,
0 xd5,
0 xb1,
0 x18,
0 xe6,
0 x63,
0 x18,
0 x86,
0 x61,
0 x18,
0 x8e,
0 xa5,
0 x1a,
0 x86,
0 x61,
0 x18,
0 x86,
0 x61,
0 x8e,
0 xed,
0 x57,
0 x0d,
0 xc3,
0 x30,
0 x0c,
0 xc3,
0 xb0,
0 xc1,
0 x79,
0 x0b,
0 x91,
0 x3e,
0 x40,
0 x6c,
0 x1c,
0 x00,
0 x90,
0 xd6,
0 x3b,
0 x00,
0 x50,
0 x96,
0 x31,
0 x53,
0 xe6,
0 x2c,
0 x59,
0 xb3,
0 x65,
0 xcf,
0 x91,
0 x33,
0 x57,
0 x31,
0 x03,
])
);
},
100 );
// This function is handled within the httpserver where setTimeout is
// available.
// eslint-disable-next-line mozilla/no-arbitrary-setTimeout, no-undef
setTimeout(
function () {
resp.end(
Buffer.from([
0 x98,
0 x00,
0 x08,
0 x3c,
0 x2f,
0 x64,
0 x69,
0 x76,
0 x3e,
0 x3c,
0 x64,
0 x69,
0 x76,
0 x3e,
0 x65,
0 x6e,
0 x64,
0 x3c,
0 x2f,
0 x64,
0 x69,
0 x76,
0 x3e,
0 x03,
])
);
},
2500 );
});
chan = makeChan(`https:
//localhost:${server.port()}/test`);
await
new Promise(resolve => {
chan.asyncOpen(
new channelListener(() => resolve()));
});
equal(
endChunk2ReceivedInTime,
true ,
"End of chunk 2 not received before chunk 3 was sent"
);
});
Messung V0.5 in Prozent C=90 H=94 G=91
¤ Dauer der Verarbeitung: 0.18 Sekunden
(vorverarbeitet am 2026-06-05)
¤
*© Formatika GbR, Deutschland