Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -916,8 +916,6 @@ function socketOnError(e) {
}

function onParserExecuteCommon(server, socket, parser, state, ret, d) {
resetSocketTimeout(server, socket, state);

if (ret instanceof Error) {
prepareError(ret, parser, d);
debug('parse error', ret);
Expand Down
41 changes: 41 additions & 0 deletions test/parallel/test-http-keep-alive-empty-line.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import * as common from '../common/index.mjs';
import assert from 'node:assert';
import { createServer } from 'node:http';
import { connect } from 'node:net';

const server = createServer({
connectionsCheckingInterval: 100,
headersTimeout: 100,
keepAliveTimeout: 300
}, (req, res) => {
res.writeHead(404);
res.end();

req.socket.on('close', common.mustCall(() => {
server.close();
}));
});

server.listen(0);

const client = connect({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would create the connection after the server emits the 'listening' event.

host: 'localhost',
port: server.address().port,
}, () => {
client.write(
'GET / HTTP/1.1\r\n' +
'Host: localhost:3000\r\n' +
'Content-Length: 0\r\n' +
'\r\n'
);

setTimeout(() => {
client.write('\r\n');
}, 100);

client.on('data', (data) => {
const status = data.toString().split(' ')[1];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no guarantee that all data will be received in a single chunk.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx, fixed test code.

assert.strictEqual(status, '404');
});
client.on('end', common.mustCall());
});
Loading