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 <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>
This commit is contained in:
parent
3d9d1ade2a
commit
be26f6e9d5
@ -406,6 +406,7 @@ function connectionListenerInternal(server, socket) {
|
|||||||
|
|
||||||
// Override on to unconsume on `data`, `readable` listeners
|
// Override on to unconsume on `data`, `readable` listeners
|
||||||
socket.on = socketOnWrap;
|
socket.on = socketOnWrap;
|
||||||
|
socket.addListener = socket.on;
|
||||||
|
|
||||||
// We only consume the socket if it has never been consumed before.
|
// We only consume the socket if it has never been consumed before.
|
||||||
if (socket._handle && socket._handle.isStreamBase &&
|
if (socket._handle && socket._handle.isStreamBase &&
|
||||||
@ -756,7 +757,9 @@ function unconsume(parser, socket) {
|
|||||||
function socketOnWrap(ev, fn) {
|
function socketOnWrap(ev, fn) {
|
||||||
const res = net.Socket.prototype.on.call(this, ev, fn);
|
const res = net.Socket.prototype.on.call(this, ev, fn);
|
||||||
if (!this.parser) {
|
if (!this.parser) {
|
||||||
|
this.prependListener = net.Socket.prototype.prependListener;
|
||||||
this.on = net.Socket.prototype.on;
|
this.on = net.Socket.prototype.on;
|
||||||
|
this.addListener = this.on;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,10 @@ const server = http.createServer(function(req, res) {
|
|||||||
received += data;
|
received += data;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
assert.strictEqual(req.socket.on, req.socket.addListener);
|
||||||
|
assert.strictEqual(req.socket.prependListener,
|
||||||
|
net.Socket.prototype.prependListener);
|
||||||
|
|
||||||
server.close();
|
server.close();
|
||||||
}).listen(0, function() {
|
}).listen(0, function() {
|
||||||
const socket = net.connect(this.address().port, function() {
|
const socket = net.connect(this.address().port, function() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user