|
| 1 | +'use strict'; |
| 2 | +const common = require('../common'); |
| 3 | +if (!common.hasCrypto) |
| 4 | + common.skip('missing crypto'); |
| 5 | +const assert = require('assert'); |
| 6 | +const http2 = require('http2'); |
| 7 | +const makeDuplexPair = require('../common/duplexpair'); |
| 8 | +const { 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 | + |
| 13 | +if (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 | +} |
0 commit comments