Skip to content

Commit

Permalink
test: make HTTP/1.0 connection test more robust
Browse files Browse the repository at this point in the history
Fixes: #47200

Co-authored-by: Luigi Pinca <[email protected]>
PR-URL: #55959
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Jason Zhang <[email protected]>
  • Loading branch information
FliegendeWurst and lpinca authored Nov 24, 2024
1 parent 1d0738a commit b6fe731
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

Expand Down Expand Up @@ -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);
});
}

Expand All @@ -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();
});
});
Expand Down

0 comments on commit b6fe731

Please sign in to comment.