1'use strict'; 2const common = require('../common'); 3if (!common.hasCrypto) 4 common.skip('missing crypto'); 5 6const tls = require('tls'); 7const http = require('http'); 8 9// Tests that, after the HTTP parser stopped owning a socket that emits an 10// 'upgrade' event, another C++ stream can start owning it (e.g. a TLSSocket). 11 12const server = http.createServer(common.mustNotCall()); 13 14server.on('upgrade', common.mustCall((request, socket, head) => { 15 // This should not crash. 16 new tls.TLSSocket(socket); 17 server.close(); 18 socket.destroy(); 19})); 20 21server.listen(0, common.mustCall(() => { 22 http.get({ 23 port: server.address().port, 24 headers: { 25 'Connection': 'Upgrade', 26 'Upgrade': 'websocket' 27 } 28 }).on('error', () => {}); 29})); 30