test: make HTTP/1.0 connection test more robust

Fixes: https://github.com/nodejs/node/issues/47200

Co-authored-by: Luigi Pinca <luigipinca@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/55959
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Jason Zhang <xzha4350@gmail.com>
pull/55988/head
Arne Keller 2024-11-24 23:30:38 +01:00 committed by GitHub
parent 1d0738a85e
commit b6fe731c55
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 6 deletions

View File

@ -10,6 +10,13 @@ const server = http.createServer(function(request, response) {
// For HTTP/1.0, the connection should be closed after the response automatically.
response.removeHeader('connection');
if (request.httpVersion === '1.0') {
const socket = request.socket;
response.on('finish', common.mustCall(function() {
assert.ok(socket.writableEnded);
}));
}
response.end('beep boop\n');
});
@ -50,9 +57,7 @@ function makeHttp10Request(cb) {
'\r\n');
socket.resume(); // Ignore the response itself
setTimeout(function() {
cb(socket);
}, common.platformTimeout(50));
socket.on('close', cb);
});
}
@ -62,9 +67,7 @@ server.listen(0, function() {
// Both HTTP/1.1 requests should have used the same socket:
assert.strictEqual(firstSocket, secondSocket);
makeHttp10Request(function(socket) {
// The server should have immediately closed the HTTP/1.0 socket:
assert.strictEqual(socket.closed, true);
makeHttp10Request(function() {
server.close();
});
});