1// Flags: --expose-internals 2 3'use strict'; 4 5const common = require('../common'); 6if (!common.hasCrypto) 7 common.skip('missing crypto'); 8const h2 = require('http2'); 9const { kSocket } = require('internal/http2/util'); 10 11const body = 12 '<html><head></head><body><h1>this is some data</h2></body></html>'; 13 14const server = h2.createServer(); 15 16// We use the lower-level API here 17server.on('stream', common.mustCall((stream) => { 18 stream.on('aborted', common.mustCall()); 19 stream.on('close', common.mustCall()); 20 stream.respond(); 21 stream.write(body); 22 // Purposefully do not end() 23})); 24 25server.listen(0, common.mustCall(function() { 26 const client = h2.connect(`http://localhost:${this.address().port}`); 27 const req = client.request(); 28 29 req.on('response', common.mustCall(() => { 30 // Send a premature socket close 31 client[kSocket].destroy(); 32 })); 33 34 req.resume(); 35 req.on('end', common.mustCall()); 36 req.on('close', common.mustCall(() => server.close())); 37 38 // On the client, the close event must call 39 client.on('close', common.mustCall()); 40})); 41