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 <luigipinca@gmail.com>
PR-URL: #55959
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Jason Zhang <xzha4350@gmail.com>
  • Loading branch information
2 people authored and aduh95 committed Nov 26, 2024
1 parent 288416a commit f7567d4
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 f7567d4

Please sign in to comment.