1'use strict'; 2 3const common = require('../common'); 4if (!common.hasCrypto) 5 common.skip('missing crypto'); 6const h2 = require('http2'); 7 8class MyServerResponse extends h2.Http2ServerResponse { 9 status(code) { 10 return this.writeHead(code, { 'Content-Type': 'text/plain' }); 11 } 12} 13 14const server = h2.createServer({ 15 Http2ServerResponse: MyServerResponse 16}, (req, res) => { 17 res.status(200); 18 res.end(); 19}); 20server.listen(0); 21 22server.on('listening', common.mustCall(() => { 23 24 const client = h2.connect(`http://localhost:${server.address().port}`); 25 const req = client.request({ ':path': '/' }); 26 27 req.on('response', common.mustCall()); 28 29 req.resume(); 30 req.on('end', common.mustCall(() => { 31 server.close(); 32 client.destroy(); 33 })); 34})); 35