Skip to content
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
16 changes: 16 additions & 0 deletions lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,22 @@ function parserOnIncoming(server, socket, state, req, keepAlive) {
});
}

if (req.method === 'HEAD' || req.method === 'GET') {
// Fast dump where request "has" already emitted all lifecycle events.
// This avoids a lot of unnecessary overhead otherwise introduced by
// stream.Readable life cycle rules. The downside is that this will
// break some servers that read GET bodies.

req._dumped = true;
req._readableState.ended = true;
req._readableState.endEmitted = true;
req._readableState.destroyed = true;
req._readableState.closed = true;
req._readableState.closeEmitted = true;
Copy link
Member

Choose a reason for hiding this comment

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

Maybe move this stream internal handling into some function exported by the stream implementation?

Copy link
Member Author

Choose a reason for hiding this comment

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

_dumped is specific to http.

Copy link
Member

Choose a reason for hiding this comment

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

I refer to all the req._readableState.* assignments which are not http specific to my knowledge. The look more like stream internals.


req._read();
}

if (socket._httpMessage) {
// There are already pending outgoing res, append.
state.outgoing.push(res);
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http-chunk-extensions-limit.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const assert = require('assert');
}));

sock.end('' +
'GET / HTTP/1.1\r\n' +
'PUT / HTTP/1.1\r\n' +
`Host: localhost:${port}\r\n` +
'Transfer-Encoding: chunked\r\n\r\n' +
'2;' + 'A'.repeat(10000) + '=bar\r\nAA\r\n' +
Expand Down
12 changes: 9 additions & 3 deletions test/parallel/test-http.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,18 @@ const server = http.Server(common.mustCall((req, res) => {
if (expectedRequests.length === 0)
server.close();

req.on('end', () => {
if (req.readableEnded) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write(`The path was ${url.parse(req.url).pathname}`);
res.end();
});
req.resume();
} else {
req.on('end', () => {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write(`The path was ${url.parse(req.url).pathname}`);
res.end();
});
req.resume();
}
}, 3));
server.listen(0);

Expand Down