Skip to content
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

lib: add an alias at addListener on Server connection socket #27325

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
himself65 marked this conversation as resolved.
Show resolved Hide resolved
assert.strictEqual(req.socket.prependListener,
net.Socket.prototype.prependListener);

server.close();
}).listen(0, function() {
const socket = net.connect(this.address().port, function() {
Expand Down