diff --git a/lib/_http_server.js b/lib/_http_server.js index ff29b9d2b60262..7b8cd6fa5e196f 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -394,6 +394,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 && @@ -744,7 +745,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() {