Skip to content

Commit 350b680

Browse files
committed
fix test
1 parent c3212f4 commit 350b680

1 file changed

Lines changed: 27 additions & 18 deletions

File tree

test/parallel/test-http-keep-alive-empty-line.mjs

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,35 @@ const server = createServer({
1616
}));
1717
});
1818

19-
server.listen(0);
19+
server.listen(0, () => {
20+
const client = connect({
21+
host: 'localhost',
22+
port: server.address().port,
23+
}, () => {
24+
client.write(
25+
'GET / HTTP/1.1\r\n' +
26+
'Host: localhost:3000\r\n' +
27+
'Content-Length: 0\r\n' +
28+
'\r\n'
29+
);
2030

21-
const client = connect({
22-
host: 'localhost',
23-
port: server.address().port,
24-
}, () => {
25-
client.write(
26-
'GET / HTTP/1.1\r\n' +
27-
'Host: localhost:3000\r\n' +
28-
'Content-Length: 0\r\n' +
29-
'\r\n'
30-
);
31+
setTimeout(() => {
32+
client.write('\r\n');
33+
}, 100);
3134

32-
setTimeout(() => {
33-
client.write('\r\n');
34-
}, 100);
35+
let responseBuffer = '';
3536

36-
client.on('data', (data) => {
37-
const status = data.toString().split(' ')[1];
38-
assert.strictEqual(status, '404');
37+
client.on('data', (chunk) => {
38+
responseBuffer += chunk.toString();
39+
40+
// Check if we've received the full header (ending with \r\n\r\n)
41+
if (responseBuffer.includes('\r\n\r\n')) {
42+
const statusLine = responseBuffer.split('\r\n')[0];
43+
const status = statusLine.split(' ')[1];
44+
assert.strictEqual(status, '404');
45+
client.end();
46+
}
47+
});
48+
client.on('end', common.mustCall());
3949
});
40-
client.on('end', common.mustCall());
4150
});

0 commit comments

Comments
 (0)