mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
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: https://github.com/nodejs/node/pull/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>
This commit is contained in:
2 files changed
+15
-2
No files matched your search
+1
-2
@@ -365,8 +365,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!');
|
||||
}
|
||||
Reference in new issue
Block a user