-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http: free the parser before emitting 'upgrade'
Ensure that the parser is freed before emitting the 'connect' or 'upgrade' event. PR-URL: #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>
- Loading branch information
1 parent
bf88a08
commit 94a954a
Showing
2 changed files
with
34 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'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(); | ||
})); | ||
})); |