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

Function parserOnIncoming

lib/_http_server.js:1256–1387  ·  view source on GitHub ↗
(server, socket, state, req, keepAlive)

Source from the content-addressed store, hash-verified

1254// new message. In this callback we setup the response object and pass it
1255// to the user.
1256function parserOnIncoming(server, socket, state, req, keepAlive) {
1257 resetSocketTimeout(server, socket, state);
1258
1259 if (req.upgrade) {
1260 req.upgrade = req.method === 'CONNECT' ||
1261 !!server.shouldUpgradeCallback(req);
1262 if (req.upgrade) {
1263 return 0;
1264 }
1265 }
1266
1267 state.incoming.push(req);
1268
1269 // If the writable end isn't consuming, then stop reading
1270 // so that we don't become overwhelmed by a flood of
1271 // pipelined requests that may never be resolved.
1272 if (!socket._paused) {
1273 const ws = socket._writableState;
1274 if (ws.needDrain || state.outgoingData >= socket.writableHighWaterMark) {
1275 socket._paused = true;
1276 // We also need to pause the parser, but don't do that until after
1277 // the call to execute, because we may still be processing the last
1278 // chunk.
1279 socket.pause();
1280 }
1281 }
1282
1283 const res = new server[kServerResponse](req,
1284 {
1285 highWaterMark: socket.writableHighWaterMark,
1286 rejectNonStandardBodyWrites: server.rejectNonStandardBodyWrites,
1287 });
1288 res._keepAliveTimeout = server.keepAliveTimeout;
1289 res._maxRequestsPerSocket = server.maxRequestsPerSocket;
1290 res._onPendingData = updateOutgoingData.bind(undefined,
1291 socket, state);
1292
1293 res.shouldKeepAlive = keepAlive;
1294 res[kUniqueHeaders] = server[kUniqueHeaders];
1295
1296 if (onRequestStartChannel.hasSubscribers) {
1297 onRequestStartChannel.publish({
1298 request: req,
1299 response: res,
1300 socket,
1301 server,
1302 });
1303 }
1304
1305 // Check if we should optimize empty requests (those without Content-Length or Transfer-Encoding headers)
1306 const shouldOptimize = server[kOptimizeEmptyRequests] === true && !hasBodyHeaders(req.headers);
1307
1308 if (shouldOptimize) {
1309 // Fast processing where emitting 'data', 'end' and 'close' events is
1310 // skipped and data is dumped.
1311 // This avoids a lot of unnecessary overhead otherwise introduced by
1312 // stream.Readable life cycle rules. The downside is that this will
1313 // break some servers that read bodies for methods that don't have body headers.

Callers

nothing calls this directly

Calls 14

resetSocketTimeoutFunction · 0.85
hasBodyHeadersFunction · 0.85
writeHeadMethod · 0.80
listenerCountMethod · 0.80
writeContinueMethod · 0.80
pauseMethod · 0.65
pushMethod · 0.45
bindMethod · 0.45
publishMethod · 0.45
_readMethod · 0.45
onMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…