Skip to content

Commit

Permalink
http: add an alias at addListener on Server connection socket
Browse files Browse the repository at this point in the history
Fixes: #27199

PR-URL: #27325
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
himself65 authored and targos committed May 20, 2019
1 parent 6070e88 commit 4a9af17
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 4 additions & 0 deletions test/parallel/test-http-server-unconsume.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 4a9af17

Please sign in to comment.