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

Function requestOnConnect

lib/internal/http2/core.js:779–846  ·  view source on GitHub ↗
(headersList, options)

Source from the content-addressed store, hash-verified

777// connected. If request() is called during this time, the actual request
778// will be deferred until the socket is ready to go.
779function requestOnConnect(headersList, options) {
780 const session = this[kSession];
781
782 // At this point, the stream should have already been destroyed during
783 // the session.destroy() method. Do nothing else.
784 if (session === undefined || session.destroyed)
785 return;
786
787 // If the session was closed while waiting for the connect, destroy
788 // the stream and do not continue with the request.
789 if (session.closed) {
790 const err = new ERR_HTTP2_GOAWAY_SESSION();
791 this.destroy(err);
792 return;
793 }
794
795 debugSessionObj(session, 'connected, initializing request');
796
797 let streamOptions = 0;
798 if (options.endStream)
799 streamOptions |= STREAM_OPTION_EMPTY_PAYLOAD;
800
801 if (options.waitForTrailers)
802 streamOptions |= STREAM_OPTION_GET_TRAILERS;
803
804 deprecateWeight(options);
805
806 // `ret` will be either the reserved stream ID (if positive)
807 // or an error code (if negative)
808 const ret = session[kHandle].request(headersList,
809 streamOptions,
810 options.parent | 0,
811 NGHTTP2_DEFAULT_WEIGHT,
812 !!options.exclusive);
813
814 // In an error condition, one of three possible response codes will be
815 // possible:
816 // * NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE - Maximum stream ID is reached, this
817 // is fatal for the session
818 // * NGHTTP2_ERR_INVALID_ARGUMENT - Stream was made dependent on itself, this
819 // impacts on this stream.
820 // For the first two, emit the error on the session,
821 // For the third, emit the error on the stream, it will bubble up to the
822 // session if not handled.
823 if (typeof ret === 'number') {
824 let err;
825 switch (ret) {
826 case NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE:
827 err = new ERR_HTTP2_OUT_OF_STREAMS();
828 this.destroy(err);
829 break;
830 case NGHTTP2_ERR_INVALID_ARGUMENT:
831 err = new ERR_HTTP2_STREAM_SELF_DEPENDENCY();
832 this.destroy(err);
833 break;
834 default:
835 session.destroy(new NghttpError(ret));
836 }

Callers

nothing calls this directly

Calls 5

debugSessionObjFunction · 0.85
requestMethod · 0.65
destroyMethod · 0.45
idMethod · 0.45
publishMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…