Skip to content
Permalink
Browse files

http: set socket.server unconditionally

This is useful for situations in which the socket was not
created for HTTP, e.g. when using arbitrary `Duplex` streams.

(The added test fails because previously, `socket.server.emit()`
would not work for emitting the `clientError` event, as
`socket.server` was `undefined`.)

PR-URL: #30571
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
addaleax authored and MylesBorins committed Nov 20, 2019
1 parent 7589486 commit 6b380cc7913b0a4c87fc9bb966073820f05df449
Showing with 15 additions and 2 deletions.
  1. +1 −2 lib/_http_server.js
  2. +14 −0 test/parallel/test-http-generic-streams.js
@@ -369,8 +369,7 @@ function connectionListenerInternal(server, socket) {

// Ensure that the server property of the socket is correctly set.
// See https://github.com/nodejs/node/issues/13435
if (socket.server === null)
socket.server = server;
socket.server = server;

// If the user has added a listener to the server,
// request, or response, then it's their responsibility.
@@ -138,3 +138,17 @@ const MakeDuplexPair = require('../common/duplexpair');
req.write(testData);
req.end();
}

// Test 5: The client sends garbage.
{
const server = http.createServer(common.mustNotCall());

const { clientSide, serverSide } = MakeDuplexPair();
server.emit('connection', serverSide);

server.on('clientError', common.mustCall());

// Send something that is not an HTTP request.
clientSide.end(
'I’m reading a book about anti-gravity. It’s impossible to put down!');
}

0 comments on commit 6b380cc

Please sign in to comment.
You can’t perform that action at this time.