Skip to content

Commit

Permalink
lib: add an alias at addListener on Server connection socket
Browse files Browse the repository at this point in the history
  • Loading branch information
himself65 committed May 2, 2019
1 parent 290faec commit 8bffe3a
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 @@ -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 &&
Expand Down Expand Up @@ -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;
}

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 8bffe3a

Please sign in to comment.