Skip to content
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);
assert.strictEqual(req.socket.prependListener,
net.Socket.prototype.prependListener);

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