1'use strict'; 2 3// Fixes: https://github.com/nodejs/node/issues/42713 4const common = require('../common'); 5if (!common.hasCrypto) { 6 // Remove require('assert').fail when issue is fixed and test 7 // is moved out of the known_issues directory. 8 require('assert').fail('missing crypto'); 9 common.skip('missing crypto'); 10} 11const assert = require('assert'); 12const http2 = require('http2'); 13 14const { 15 HTTP2_HEADER_PATH, 16 HTTP2_HEADER_STATUS, 17 HTTP2_HEADER_METHOD, 18} = http2.constants; 19 20const server = http2.createServer(); 21server.on('stream', common.mustCall((stream) => { 22 server.close(); 23 stream.session.close(); 24 stream.on('wantTrailers', common.mustCall(() => { 25 stream.sendTrailers({ xyz: 'abc' }); 26 })); 27 28 stream.respond({ [HTTP2_HEADER_STATUS]: 200 }, { waitForTrailers: true }); 29 stream.write('some data'); 30 stream.end(); 31})); 32 33server.listen(0, common.mustCall(() => { 34 const port = server.address().port; 35 const client = http2.connect(`http://localhost:${port}`); 36 client.socket.on('close', common.mustCall()); 37 const req = client.request({ 38 [HTTP2_HEADER_PATH]: '/', 39 [HTTP2_HEADER_METHOD]: 'POST', 40 }); 41 req.end(); 42 req.on('response', common.mustCall()); 43 let data = ''; 44 req.on('data', (chunk) => { 45 data += chunk; 46 }); 47 req.on('end', common.mustCall(() => { 48 assert.strictEqual(data, 'some data'); 49 })); 50 req.on('trailers', common.mustCall((headers) => { 51 assert.strictEqual(headers.xyz, 'abc'); 52 })); 53 req.on('close', common.mustCall()); 54})); 55