-
Notifications
You must be signed in to change notification settings - Fork 30.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
http: relax requirements on upgrade listener #19981
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -530,14 +530,14 @@ function onParserExecuteCommon(server, socket, parser, state, ret, d) { | |
parser = null; | ||
|
||
var eventName = req.method === 'CONNECT' ? 'connect' : 'upgrade'; | ||
if (server.listenerCount(eventName) > 0) { | ||
if (eventName === 'upgrade' || server.listenerCount(eventName) > 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you combine this if with the ternary before somehow? With this change we truly only need to do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we can combine it with the ternary since the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I said, I'm not convinced. Removing the ternary might create code that is harder to read in the end. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mcollina ... are you ok with this landing without this change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be clear, I would be happy to make a change but I'm not sure what it would be. I don't think there's a way to simplify this since There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only thing I can think of is reversing the condition but it doesn't change anything. if (eventName === 'connect' && server.listenerCount('connect') === 0) {
socket.destroy();
} else {
// ...
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes definitely. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can land |
||
debug('SERVER have listener for %s', eventName); | ||
var bodyHead = d.slice(bytesParsed, d.length); | ||
|
||
socket.readableFlowing = null; | ||
server.emit(eventName, req, socket, bodyHead); | ||
} else { | ||
// Got upgrade header or CONNECT method, but have no handler. | ||
// Got CONNECT method, but have no handler. | ||
socket.destroy(); | ||
} | ||
} | ||
|
@@ -592,6 +592,13 @@ function resOnFinish(req, res, socket, state, server) { | |
function parserOnIncoming(server, socket, state, req, keepAlive) { | ||
resetSocketTimeout(server, socket, state); | ||
|
||
if (req.upgrade) { | ||
req.upgrade = req.method === 'CONNECT' || | ||
server.listenerCount('upgrade') > 0; | ||
if (req.upgrade) | ||
return 2; | ||
} | ||
|
||
state.incoming.push(req); | ||
|
||
// If the writable end isn't consuming, then stop reading | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,8 +121,6 @@ function test_upgrade_with_listener() { | |
/*----------------------------------------------- | ||
connection: Upgrade, no listener | ||
-----------------------------------------------*/ | ||
let test_upgrade_no_listener_ended = false; | ||
|
||
function test_upgrade_no_listener() { | ||
const conn = net.createConnection(server.address().port); | ||
conn.setEncoding('utf8'); | ||
|
@@ -135,8 +133,9 @@ function test_upgrade_no_listener() { | |
'\r\n'); | ||
}); | ||
|
||
conn.on('end', function() { | ||
test_upgrade_no_listener_ended = true; | ||
conn.once('data', (data) => { | ||
assert.strictEqual('string', typeof data); | ||
assert.strictEqual('HTTP/1.1 200', data.substr(0, 12)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: please switch the arguments order to adhere to |
||
conn.end(); | ||
}); | ||
|
||
|
@@ -182,5 +181,4 @@ server.listen(0, function() { | |
process.on('exit', function() { | ||
assert.strictEqual(3, requests_recv); | ||
assert.strictEqual(3, requests_sent); | ||
assert.ok(test_upgrade_no_listener_ended); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add the comment:
It was there in
_http_common.js