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

Function parserOnIncomingClient

lib/_http_client.js:718–824  ·  view source on GitHub ↗
(res, shouldKeepAlive)

Source from the content-addressed store, hash-verified

716
717// client
718function parserOnIncomingClient(res, shouldKeepAlive) {
719 const socket = this.socket;
720 const req = socket._httpMessage;
721
722 debug('AGENT incoming response!');
723
724 if (req.res) {
725 // We already have a response object, this means the server
726 // sent a double response.
727 socket.destroy();
728 if (socket.parser) {
729 // https://github.com/nodejs/node/issues/60025
730 // Now, parser.incoming is pointed to the new IncomingMessage,
731 // we need to rewrite it to the first one and skip all the pending IncomingMessage
732 socket.parser.incoming = req.res;
733 socket.parser.incoming[kSkipPendingData] = true;
734 }
735 return 0;
736 }
737 req.res = res;
738
739 // Skip body and treat as Upgrade.
740 if (res.upgrade)
741 return 2;
742
743 // Responses to CONNECT request is handled as Upgrade.
744 const method = req.method;
745 if (method === 'CONNECT') {
746 res.upgrade = true;
747 return 2; // Skip body and treat as Upgrade.
748 }
749
750 if (statusIsInformational(res.statusCode)) {
751 // Restart the parser, as this is a 1xx informational message.
752 req.res = null; // Clear res so that we don't hit double-responses.
753 // Maintain compatibility by sending 100-specific events
754 if (res.statusCode === 100) {
755 req.emit('continue');
756 }
757 // Send information events to all 1xx responses except 101 Upgrade.
758 req.emit('information', {
759 statusCode: res.statusCode,
760 statusMessage: res.statusMessage,
761 httpVersion: res.httpVersion,
762 httpVersionMajor: res.httpVersionMajor,
763 httpVersionMinor: res.httpVersionMinor,
764 headers: res.headers,
765 rawHeaders: res.rawHeaders,
766 });
767
768 return 1; // Skip body but don't treat as Upgrade.
769 }
770
771 if (req.shouldKeepAlive && !shouldKeepAlive && !req.upgradeOrConnect) {
772 // Server MUST respond with Connection:keep-alive for us to enable it.
773 // If we've been upgraded (via WebSockets) we also shouldn't try to
774 // keep the connection open.
775 req.shouldKeepAlive = false;

Callers

nothing calls this directly

Calls 11

statusIsInformationalFunction · 0.85
hasObserverFunction · 0.85
stopPerfFunction · 0.85
isTraceHTTPEnabledFunction · 0.85
traceEndFunction · 0.85
debugFunction · 0.50
destroyMethod · 0.45
emitMethod · 0.45
publishMethod · 0.45
onMethod · 0.45
_dumpMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…