Skip to content

Commit

Permalink
http: reset headers timeout on headers complete
Browse files Browse the repository at this point in the history
headers timeout should not occur *after* headers have been
received.

Fixes: #34576

PR-URL: #34578
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Fedor Indutny <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Pranshu Srivastava <[email protected]>
  • Loading branch information
ronag authored and codebytere committed Aug 5, 2020
1 parent d7eaf3a commit 7322e58
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/node_http_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ class Parser : public AsyncWrap, public StreamListener {

int on_headers_complete() {
header_nread_ = 0;
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
46 changes: 46 additions & 0 deletions test/parallel/test-http-parser-timeout-reset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
'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,
{},
0,
false,
1e3
);

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

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

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

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

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

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

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

0 comments on commit 7322e58

Please sign in to comment.