From be26f6e9d5e8f39048549fa4f18eef49adff3e55 Mon Sep 17 00:00:00 2001 From: himself65 Date: Sat, 20 Apr 2019 22:42:27 +0800 Subject: [PATCH] http: add an alias at addListener on Server connection socket Fixes: https://github.com/nodejs/node/issues/27199 PR-URL: https://github.com/nodejs/node/pull/27325 Reviewed-By: Anna Henningsen Reviewed-By: Ruben Bridgewater Reviewed-By: Colin Ihrig Reviewed-By: Luigi Pinca Reviewed-By: James M Snell Reviewed-By: Anatoli Papirovski Reviewed-By: Yongsheng Zhang Reviewed-By: Rich Trott --- lib/_http_server.js | 3 +++ test/parallel/test-http-server-unconsume.js | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/lib/_http_server.js b/lib/_http_server.js index f7884d2626f499..62b58dd2e1e000 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -406,6 +406,7 @@ function connectionListenerInternal(server, socket) { // Override on to unconsume on `data`, `readable` listeners socket.on = socketOnWrap; + socket.addListener = socket.on; // We only consume the socket if it has never been consumed before. if (socket._handle && socket._handle.isStreamBase && @@ -756,7 +757,9 @@ function unconsume(parser, socket) { function socketOnWrap(ev, fn) { const res = net.Socket.prototype.on.call(this, ev, fn); if (!this.parser) { + this.prependListener = net.Socket.prototype.prependListener; this.on = net.Socket.prototype.on; + this.addListener = this.on; return res; } diff --git a/test/parallel/test-http-server-unconsume.js b/test/parallel/test-http-server-unconsume.js index 9f80e9ea82de48..c285a53c7ac215 100644 --- a/test/parallel/test-http-server-unconsume.js +++ b/test/parallel/test-http-server-unconsume.js @@ -14,6 +14,10 @@ const server = http.createServer(function(req, res) { received += data; }); + assert.strictEqual(req.socket.on, req.socket.addListener); + assert.strictEqual(req.socket.prependListener, + net.Socket.prototype.prependListener); + server.close(); }).listen(0, function() { const socket = net.connect(this.address().port, function() {