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
  • Loading branch information
FliegendeWurst authored Nov 22, 2024
1 parent 02921e1 commit b6671e5
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,20 @@ function makeHttp11Request(cb) {
function makeHttp10Request(cb) {
// We have to manually make HTTP/1.0 requests since Node does not allow sending them:
const socket = net.connect({ port: server.address().port }, function() {
socket.on('error', common.mustNotCall());

socket.write('GET / HTTP/1.0\r\n' +
'Host: localhost:' + server.address().port + '\r\n' +
'\r\n');
socket.resume(); // Ignore the response itself
socket.end(); // we are done sending data
socket.resume();

setTimeout(function() {
cb(socket);
}, common.platformTimeout(50));
// Wait for response to be sent before invoking callback
socket.on('close', function() {
setTimeout(function() {
cb(socket);
}, common.platformTimeout(100));
});
});
}

Expand All @@ -63,7 +69,8 @@ server.listen(0, function() {
assert.strictEqual(firstSocket, secondSocket);

makeHttp10Request(function(socket) {
// The server should have immediately closed the HTTP/1.0 socket:
// We waited for the HTTP response above, so
// the server should have immediately closed the HTTP/1.0 socket:
assert.strictEqual(socket.closed, true);
server.close();
});
Expand Down

0 comments on commit b6671e5

Please sign in to comment.