MCPcopy Index your code
hub / github.com/nodejs/node / testHttp2

Function testHttp2

test/parallel/test-inspector-network-http2.js:206–284  ·  view source on GitHub ↗
(secure = false)

Source from the content-addressed store, hash-verified

204}
205
206async function testHttp2(secure = false) {
207 const port = (secure ? http2SecureServer : http2Server).address().port;
208 const origin = (secure ? 'https' : 'http') + `://localhost:${port}`;
209 const url = `${origin}/hello-world`;
210 const pushedUrl = `${origin}/style.css`;
211
212 const requestWillBeSent = on(session, 'Network.requestWillBeSent');
213 const responseReceived = on(session, 'Network.responseReceived');
214 const loadingFinished = on(session, 'Network.loadingFinished');
215
216 session.on('Network.loadingFailed', common.mustNotCall());
217
218 const client = http2.connect(origin, {
219 rejectUnauthorized: false,
220 });
221 const request = client.request(requestHeaders);
222 request.write(JSON.stringify(requestBody));
223 request.end();
224
225 // Dump the responses.
226 request.on('data', () => {});
227 client.on('stream', (pushStream) => {
228 pushStream.on('data', () => {});
229 });
230 request.on('end', () => {
231 client.close();
232 });
233 request.end();
234
235 const [
236 { value: [ mainRequest ] },
237 { value: [ pushRequest ] },
238 ] = await Promise.all([requestWillBeSent.next(), requestWillBeSent.next()]);
239 verifyRequestWillBeSent(mainRequest, url);
240 verifyRequestWillBeSent(pushRequest, pushedUrl);
241
242 const { postData } = await session.post('Network.getRequestPostData', {
243 requestId: mainRequest.params.requestId
244 });
245 assert.strictEqual(postData, JSON.stringify(requestBody));
246
247 const [
248 { value: [ mainResponse ] },
249 { value: [ pushResponse ] },
250 ] = await Promise.all([responseReceived.next(), responseReceived.next()]);
251 verifyResponseReceived(mainResponse, url);
252 verifyResponseReceived(pushResponse, pushedUrl);
253
254 const [
255 { value: [ event1 ] },
256 { value: [ event2 ] },
257 ] = await Promise.all([loadingFinished.next(), loadingFinished.next()]);
258 verifyLoadingFinished(event1);
259 verifyLoadingFinished(event2);
260
261 const responseBody = await session.post('Network.getResponseBody', {
262 requestId: mainRequest.params.requestId,
263 });

Callers 1

testNetworkInspectionFunction · 0.85

Calls 15

allMethod · 0.80
verifyRequestWillBeSentFunction · 0.70
verifyResponseReceivedFunction · 0.70
verifyLoadingFinishedFunction · 0.70
addressMethod · 0.65
connectMethod · 0.65
requestMethod · 0.65
closeMethod · 0.65
nextMethod · 0.65
findMethod · 0.65
onFunction · 0.50
onMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…