Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v12.x backport] http: reset headers timeout on headers complete #35819

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions src/node_http_parser_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ class Parser : public AsyncWrap, public StreamListener {
#ifdef NODE_EXPERIMENTAL_HTTP
header_nread_ = 0;
#endif /* NODE_EXPERIMENTAL_HTTP */
header_parsing_start_time_ = 0;

// Arguments for the on-headers-complete javascript callback. This
// list needs to be kept in sync with the actual argument list for
Expand Down
44 changes: 44 additions & 0 deletions test/parallel/test-http-parser-timeout-reset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
'use strict';
const common = require('../common');

const net = require('net');
const { HTTPParser } = process.binding('http_parser');

const server = net.createServer((socket) => {
socket.write('HTTP/1.1 200 OK\r\n');
socket.write('Transfer-Encoding: chunked\r\n\r\n');
setTimeout(() => {
socket.write('1\r\n');
socket.write('\n\r\n');
setTimeout(() => {
socket.write('1\r\n');
socket.write('\n\r\n');
setImmediate(() => {
socket.destroy();
server.close();
});
}, 500);
}, 500);
}).listen(0, () => {
const socket = net.connect(server.address().port);
const parser = new HTTPParser(HTTPParser.RESPONSE, false);
parser.initialize(
HTTPParser.RESPONSE,
{},
1e3
);

parser[HTTPParser.kOnTimeout] = common.mustNotCall();

parser[HTTPParser.kOnHeaders] = common.mustNotCall();

parser[HTTPParser.kOnExecute] = common.mustCallAtLeast(3);

parser[HTTPParser.kOnHeadersComplete] = common.mustCall();

parser[HTTPParser.kOnBody] = common.mustCall(2);

parser[HTTPParser.kOnMessageComplete] = common.mustNotCall();

parser.consume(socket._handle);
});