0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-29 23:16:30 +01:00
nodejs/test/parallel/test-http-parser-freed-before-upgrade.js
Luigi Pinca 93f1d9e10b
http: free the parser before emitting 'upgrade'
Ensure that the parser is freed before emitting the 'connect' or
'upgrade' event.

PR-URL: https://github.com/nodejs/node/pull/18209
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2018-01-21 02:42:19 +01:00

34 lines
750 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const http = require('http');
const server = http.createServer();
server.on('upgrade', common.mustCall((request, socket) => {
assert.strictEqual(socket.parser, null);
socket.write([
'HTTP/1.1 101 Switching Protocols',
'Connection: Upgrade',
'Upgrade: WebSocket',
'\r\n'
].join('\r\n'));
}));
server.listen(common.mustCall(() => {
const request = http.get({
port: server.address().port,
headers: {
Connection: 'Upgrade',
Upgrade: 'WebSocket'
}
});
request.on('upgrade', common.mustCall((response, socket) => {
assert.strictEqual(socket.parser, null);
socket.destroy();
server.close();
}));
}));