Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d4f0366

Browse filesBrowse files
starkwangMylesBorins
authored andcommitted
http: reduce duplicated code for cleaning parser
PR-URL: #23351 Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 1266878 commit d4f0366
Copy full SHA for d4f0366

File tree

Expand file treeCollapse file tree

1 file changed

+13
-19
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+13
-19
lines changed
Open diff view settings
Collapse file

‎lib/_http_common.js‎

Copy file name to clipboardExpand all lines: lib/_http_common.js
+13-19Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -151,22 +151,13 @@ function parserOnMessageComplete() {
151151
const parsers = new FreeList('parsers', 1000, function parsersCb() {
152152
const parser = new HTTPParser(HTTPParser.REQUEST);
153153

154-
parser._headers = [];
155-
parser._url = '';
156-
parser._consumed = false;
157-
158-
parser.socket = null;
159-
parser.incoming = null;
160-
parser.outgoing = null;
161-
162-
parser.maxHeaderPairs = MAX_HEADER_PAIRS;
154+
cleanParser(parser);
163155

164156
parser.onIncoming = null;
165157
parser[kOnHeaders] = parserOnHeaders;
166158
parser[kOnHeadersComplete] = parserOnHeadersComplete;
167159
parser[kOnBody] = parserOnBody;
168160
parser[kOnMessageComplete] = parserOnMessageComplete;
169-
parser[kOnExecute] = null;
170161

171162
return parser;
172163
});
@@ -182,17 +173,9 @@ function closeParserInstance(parser) { parser.close(); }
182173
// should be all that is needed.
183174
function freeParser(parser, req, socket) {
184175
if (parser) {
185-
parser._headers = [];
186-
parser._url = '';
187-
parser.maxHeaderPairs = MAX_HEADER_PAIRS;
188-
parser.onIncoming = null;
189176
if (parser._consumed)
190177
parser.unconsume();
191-
parser._consumed = false;
192-
parser.socket = null;
193-
parser.incoming = null;
194-
parser.outgoing = null;
195-
parser[kOnExecute] = null;
178+
cleanParser(parser);
196179
if (parsers.free(parser) === false) {
197180
// Make sure the parser's stack has unwound before deleting the
198181
// corresponding C++ object through .close().
@@ -238,6 +221,17 @@ function checkInvalidHeaderChar(val) {
238221
return headerCharRegex.test(val);
239222
}
240223

224+
function cleanParser(parser) {
225+
parser._headers = [];
226+
parser._url = '';
227+
parser.socket = null;
228+
parser.incoming = null;
229+
parser.outgoing = null;
230+
parser.maxHeaderPairs = MAX_HEADER_PAIRS;
231+
parser[kOnExecute] = null;
232+
parser._consumed = false;
233+
}
234+
241235
module.exports = {
242236
_checkInvalidHeaderChar: checkInvalidHeaderChar,
243237
_checkIsHttpToken: checkIsHttpToken,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.