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

Function socketOnData

lib/_http_client.js:640–707  ·  view source on GitHub ↗
(d)

Source from the content-addressed store, hash-verified

638}
639
640function socketOnData(d) {
641 const socket = this;
642 const req = this._httpMessage;
643 const parser = this.parser;
644
645 assert(parser && parser.socket === socket);
646
647 const ret = parser.execute(d);
648 if (ret instanceof Error) {
649 prepareError(ret, parser, d);
650 debug('parse error', ret);
651 freeParser(parser, req, socket);
652 socket.removeListener('data', socketOnData);
653 socket.removeListener('end', socketOnEnd);
654 socket.destroy();
655 req.socket._hadError = true;
656 emitErrorEvent(req, ret);
657 } else if (parser.incoming?.upgrade) {
658 // Upgrade (if status code 101) or CONNECT
659 const bytesParsed = ret;
660 const res = parser.incoming;
661 req.res = res;
662
663 socket.removeListener('data', socketOnData);
664 socket.removeListener('end', socketOnEnd);
665 socket.removeListener('drain', ondrain);
666
667 if (req.timeoutCb) socket.removeListener('timeout', req.timeoutCb);
668 socket.removeListener('timeout', responseOnTimeout);
669
670 parser.finish();
671 freeParser(parser, req, socket);
672
673 const bodyHead = d.slice(bytesParsed, d.length);
674
675 const eventName = req.method === 'CONNECT' ? 'connect' : 'upgrade';
676 if (req.listenerCount(eventName) > 0) {
677 req.upgradeOrConnect = true;
678
679 // detach the socket
680 socket.emit('agentRemove');
681 socket.removeListener('close', socketCloseListener);
682 socket.removeListener('error', socketErrorListener);
683
684 socket._httpMessage = null;
685 socket.readableFlowing = null;
686
687 req.emit(eventName, res, socket, bodyHead);
688 req.destroyed = true;
689 req._closed = true;
690 req.emit('close');
691 } else {
692 // Requested Upgrade or used CONNECT method, but have no handler.
693 socket.destroy();
694 }
695 } else if (parser.incoming?.complete &&
696 // When the status code is informational (100, 102-199),
697 // the server will send a final response after this client

Callers

nothing calls this directly

Calls 13

prepareErrorFunction · 0.85
freeParserFunction · 0.85
emitErrorEventFunction · 0.85
statusIsInformationalFunction · 0.85
listenerCountMethod · 0.80
assertFunction · 0.70
sliceMethod · 0.65
debugFunction · 0.50
executeMethod · 0.45
removeListenerMethod · 0.45
destroyMethod · 0.45
finishMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…