|
| 1 | +'use strict'; |
| 2 | +const common = require('../common'); |
| 3 | +if (!common.hasCrypto) |
| 4 | +common.skip('missing crypto'); |
| 5 | + |
| 6 | +const tls = require('tls'); |
| 7 | +const 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 | + |
| 12 | +const server = http.createServer(common.mustNotCall()); |
| 13 | + |
| 14 | +server.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 | + |
| 21 | +server.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 | +})); |