• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3if (!common.hasCrypto)
4  common.skip('missing crypto');
5const assert = require('assert');
6const http2 = require('http2');
7const makeDuplexPair = require('../common/duplexpair');
8const { Worker, isMainThread } = require('worker_threads');
9
10// This is a variant of test-http2-generic-streams-sendfile for checking
11// that Workers can be terminated during a .respondWithFile() operation.
12
13if (isMainThread) {
14  return new Worker(__filename);
15}
16
17{
18  const server = http2.createServer();
19  server.on('stream', common.mustCall((stream, headers) => {
20    stream.respondWithFile(process.execPath);  // Use a large-ish file.
21  }));
22
23  const { clientSide, serverSide } = makeDuplexPair();
24  server.emit('connection', serverSide);
25
26  const client = http2.connect('http://localhost:80', {
27    createConnection: common.mustCall(() => clientSide)
28  });
29
30  const req = client.request();
31
32  req.on('response', common.mustCall((headers) => {
33    assert.strictEqual(headers[':status'], 200);
34  }));
35
36  req.on('data', common.mustCall(process.exit));
37  req.on('end', common.mustNotCall());
38  req.end();
39}
40