MCPcopy Index your code
hub / github.com/nodejs/node / onParserExecuteCommon

Function onParserExecuteCommon

lib/_http_server.js:1098–1171  ·  view source on GitHub ↗
(server, socket, parser, state, ret, d)

Source from the content-addressed store, hash-verified

1096}
1097
1098function onParserExecuteCommon(server, socket, parser, state, ret, d) {
1099 if (ret instanceof Error) {
1100 prepareError(ret, parser, d);
1101 debug('parse error', ret);
1102 socketOnError.call(socket, ret);
1103 } else if (parser.incoming?.upgrade) {
1104 // Upgrade or CONNECT
1105 const req = parser.incoming;
1106 debug('SERVER upgrade or connect', req.method);
1107 const eventName = req.method === 'CONNECT' ? 'connect' : 'upgrade';
1108
1109 let upgradeStream;
1110 if (req.complete) {
1111 d ||= parser.getCurrentBuffer();
1112
1113 socket.removeListener('data', state.onData);
1114 socket.removeListener('end', state.onEnd);
1115 socket.removeListener('close', state.onClose);
1116 socket.removeListener('drain', state.onDrain);
1117 socket.removeListener('error', socketOnError);
1118 socket.removeListener('timeout', socketOnTimeout);
1119
1120 unconsume(parser, socket);
1121 parser.finish();
1122 freeParser(parser, req, socket);
1123 parser = null;
1124
1125 // If the request is complete (no body, or all body read upfront) then
1126 // we just emit the socket directly as the upgrade stream.
1127 upgradeStream = socket;
1128 } else {
1129 // If the body hasn't been fully parsed yet, we emit immediately but
1130 // we add a wrapper around the socket to not expose incoming data
1131 // until the request body has finished.
1132
1133 if (socket[kUpgradeStream]) {
1134 // We've already emitted the incomplete upgrade - nothing do to
1135 // until actual body parsing completion.
1136 return;
1137 }
1138
1139 d ||= Buffer.alloc(0);
1140
1141 upgradeStream = new UpgradeStream(socket, req);
1142 socket[kUpgradeStream] = upgradeStream;
1143 }
1144
1145 if (server.listenerCount(eventName) > 0) {
1146 debug('SERVER have listener for %s', eventName);
1147
1148 const bodyHead = d.slice(ret, d.length);
1149
1150 if (req.complete && socket[kUpgradeStream]) {
1151 // Previously emitted, now completed - just activate the stream
1152 socket[kUpgradeStream].requestBodyCompleted(bodyHead);
1153 } else {
1154 socket.readableFlowing = null;
1155 server.emit(eventName, req, upgradeStream, bodyHead);

Callers 2

socketOnDataFunction · 0.85
onParserExecuteFunction · 0.85

Calls 14

prepareErrorFunction · 0.85
unconsumeFunction · 0.85
freeParserFunction · 0.85
allocMethod · 0.80
listenerCountMethod · 0.80
requestBodyCompletedMethod · 0.80
sliceMethod · 0.65
pauseMethod · 0.65
debugFunction · 0.50
callMethod · 0.45
removeListenerMethod · 0.45
finishMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…