mirror of https://github.com/nodejs/node.git
http: reduce duplicated code for cleaning parser
PR-URL: https://github.com/nodejs/node/pull/23351 Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>pull/23351/merge
parent
846cc7e498
commit
d7f17b2a61
|
@ -151,22 +151,13 @@ function parserOnMessageComplete() {
|
|||
const parsers = new FreeList('parsers', 1000, function parsersCb() {
|
||||
const parser = new HTTPParser(HTTPParser.REQUEST);
|
||||
|
||||
parser._headers = [];
|
||||
parser._url = '';
|
||||
parser._consumed = false;
|
||||
|
||||
parser.socket = null;
|
||||
parser.incoming = null;
|
||||
parser.outgoing = null;
|
||||
|
||||
parser.maxHeaderPairs = MAX_HEADER_PAIRS;
|
||||
cleanParser(parser);
|
||||
|
||||
parser.onIncoming = null;
|
||||
parser[kOnHeaders] = parserOnHeaders;
|
||||
parser[kOnHeadersComplete] = parserOnHeadersComplete;
|
||||
parser[kOnBody] = parserOnBody;
|
||||
parser[kOnMessageComplete] = parserOnMessageComplete;
|
||||
parser[kOnExecute] = null;
|
||||
|
||||
return parser;
|
||||
});
|
||||
|
@ -182,17 +173,9 @@ function closeParserInstance(parser) { parser.close(); }
|
|||
// should be all that is needed.
|
||||
function freeParser(parser, req, socket) {
|
||||
if (parser) {
|
||||
parser._headers = [];
|
||||
parser._url = '';
|
||||
parser.maxHeaderPairs = MAX_HEADER_PAIRS;
|
||||
parser.onIncoming = null;
|
||||
if (parser._consumed)
|
||||
parser.unconsume();
|
||||
parser._consumed = false;
|
||||
parser.socket = null;
|
||||
parser.incoming = null;
|
||||
parser.outgoing = null;
|
||||
parser[kOnExecute] = null;
|
||||
cleanParser(parser);
|
||||
if (parsers.free(parser) === false) {
|
||||
// Make sure the parser's stack has unwound before deleting the
|
||||
// corresponding C++ object through .close().
|
||||
|
@ -238,6 +221,17 @@ function checkInvalidHeaderChar(val) {
|
|||
return headerCharRegex.test(val);
|
||||
}
|
||||
|
||||
function cleanParser(parser) {
|
||||
parser._headers = [];
|
||||
parser._url = '';
|
||||
parser.socket = null;
|
||||
parser.incoming = null;
|
||||
parser.outgoing = null;
|
||||
parser.maxHeaderPairs = MAX_HEADER_PAIRS;
|
||||
parser[kOnExecute] = null;
|
||||
parser._consumed = false;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
_checkInvalidHeaderChar: checkInvalidHeaderChar,
|
||||
_checkIsHttpToken: checkIsHttpToken,
|
||||
|
|
Loading…
Reference in New Issue