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

Function resOnFinish

lib/_http_server.js:1186–1239  ·  view source on GitHub ↗
(req, res, socket, state, server)

Source from the content-addressed store, hash-verified

1184}
1185
1186function resOnFinish(req, res, socket, state, server) {
1187 if (onResponseFinishChannel.hasSubscribers) {
1188 onResponseFinishChannel.publish({
1189 request: req,
1190 response: res,
1191 socket,
1192 server,
1193 });
1194 }
1195
1196 // Usually the first incoming element should be our request. it may
1197 // be that in the case abortIncoming() was called that the incoming
1198 // array will be empty.
1199 assert(state.incoming.length === 0 || state.incoming[0] === req);
1200
1201 state.incoming.shift();
1202
1203 // If the user never called req.read(), and didn't pipe() or
1204 // .resume() or .on('data'), then we call req._dump() so that the
1205 // bytes will be pulled off the wire.
1206 if (!req._consuming && !req._readableState.resumeScheduled)
1207 req._dump();
1208
1209 res.detachSocket(socket);
1210 clearIncoming(req);
1211 process.nextTick(emitCloseNT, res);
1212
1213 if (res._last) {
1214 if (typeof socket.destroySoon === 'function') {
1215 socket.destroySoon();
1216 } else {
1217 socket.end();
1218 }
1219 } else if (state.outgoing.length === 0) {
1220 const keepAliveTimeout = NumberIsFinite(server.keepAliveTimeout) && server.keepAliveTimeout >= 0 ?
1221 server.keepAliveTimeout : 0;
1222 const keepAliveTimeoutBuffer = NumberIsFinite(server.keepAliveTimeoutBuffer) && server.keepAliveTimeoutBuffer >= 0 ?
1223 server.keepAliveTimeoutBuffer : 1e3;
1224
1225 if (keepAliveTimeout && typeof socket.setTimeout === 'function') {
1226 // Extend the internal timeout by the configured buffer to reduce
1227 // the likelihood of ECONNRESET errors.
1228 // This allows fine-tuning beyond the advertised keepAliveTimeout.
1229 socket.setTimeout(keepAliveTimeout + keepAliveTimeoutBuffer);
1230 state.keepAliveTimeoutSet = true;
1231 }
1232 } else {
1233 // Start sending the next message
1234 const m = state.outgoing.shift();
1235 if (m) {
1236 m.assignSocket(socket);
1237 }
1238 }
1239}
1240
1241function emitCloseNT(self) {
1242 if (!self._closed) {

Callers

nothing calls this directly

Calls 7

clearIncomingFunction · 0.85
assertFunction · 0.70
publishMethod · 0.45
shiftMethod · 0.45
_dumpMethod · 0.45
endMethod · 0.45
setTimeoutMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…