Skip to content

Commit 8476537

Browse files
Trotttargos
authored andcommitted
test,http: check that http server is robust from handler abuse
The only way I could find to complete coverage for _http_common.js is to use semi-private (exposed but probably shouldn't be) handlers to get the state into something weird. With the if-condition being checked (see Refs) commented out, I get this result from this test: ``` node:_http_common:140 if (len > 0 && !stream._dumped) { ^ TypeError: Cannot read property '_dumped' of null at HTTPParser.parserOnBody (node:_http_common:140:26) ``` With the check in place, the test passes without an error. Seems like quite the edge case, but I'm going to assume it's there for a reason. Refs: https://coverage.nodejs.org/coverage-b560645d6b0a4bed/lib/_http_common.js.html#L137 PR-URL: #37958 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent b5ad655 commit 8476537

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict';
2+
const common = require('../common');
3+
const { createServer } = require('http');
4+
const { connect } = require('net');
5+
6+
// Make sure that calling the semi-private close() handlers manually doesn't
7+
// cause an error.
8+
9+
const server = createServer(common.mustCall((req, res) => {
10+
req.client._events.close.forEach((fn) => { fn.bind(req)(); });
11+
}));
12+
13+
server.unref();
14+
15+
server.listen(0, common.mustCall(() => {
16+
const client = connect(server.address().port);
17+
18+
const req = [
19+
'POST / HTTP/1.1',
20+
'Content-Length: 11',
21+
'',
22+
'hello world',
23+
].join('\r\n');
24+
25+
client.end(req);
26+
}));

0 commit comments

Comments
 (0)