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

Method pushStream

lib/internal/http2/core.js:2908–3002  ·  view source on GitHub ↗
(headers, options, callback)

Source from the content-addressed store, hash-verified

2906 // Create a push stream, call the given callback with the created
2907 // Http2Stream for the push stream.
2908 pushStream(headers, options, callback) {
2909 if (!this.pushAllowed)
2910 throw new ERR_HTTP2_PUSH_DISABLED();
2911 if (this[kID] % 2 === 0)
2912 throw new ERR_HTTP2_NESTED_PUSH();
2913
2914 const session = this[kSession];
2915
2916 debugStreamObj(this, 'initiating push stream');
2917
2918 this[kUpdateTimer]();
2919
2920 if (typeof options === 'function') {
2921 callback = options;
2922 options = undefined;
2923 }
2924
2925 validateFunction(callback, 'callback');
2926
2927 assertIsObject(options, 'options');
2928 options = { ...options };
2929 options.endStream = !!options.endStream;
2930
2931 assertIsObject(headers, 'headers');
2932 headers = ObjectAssign({ __proto__: null }, headers);
2933
2934 if (headers[HTTP2_HEADER_METHOD] === undefined)
2935 headers[HTTP2_HEADER_METHOD] = HTTP2_METHOD_GET;
2936 if (getAuthority(headers) === undefined)
2937 headers[HTTP2_HEADER_AUTHORITY] = this[kAuthority];
2938 if (headers[HTTP2_HEADER_SCHEME] === undefined)
2939 headers[HTTP2_HEADER_SCHEME] = this[kProtocol];
2940 if (headers[HTTP2_HEADER_PATH] === undefined)
2941 headers[HTTP2_HEADER_PATH] = '/';
2942
2943 let headRequest = false;
2944 if (headers[HTTP2_HEADER_METHOD] === HTTP2_METHOD_HEAD)
2945 headRequest = options.endStream = true;
2946
2947 const headersList = buildNgHeaderString(
2948 headers,
2949 assertValidPseudoHeader,
2950 this.session[kStrictSingleValueFields],
2951 );
2952
2953 const streamOptions = options.endStream ? STREAM_OPTION_EMPTY_PAYLOAD : 0;
2954
2955 const ret = this[kHandle].pushPromise(headersList, streamOptions);
2956 let err;
2957 if (typeof ret === 'number') {
2958 switch (ret) {
2959 case NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE:
2960 err = new ERR_HTTP2_OUT_OF_STREAMS();
2961 break;
2962 case NGHTTP2_ERR_STREAM_CLOSED:
2963 err = new ERR_HTTP2_INVALID_STREAM();
2964 break;
2965 default:

Calls 9

debugStreamObjFunction · 0.85
ObjectAssignFunction · 0.85
getAuthorityFunction · 0.85
buildNgHeaderStringFunction · 0.85
callbackFunction · 0.50
idMethod · 0.45
pushMethod · 0.45
endMethod · 0.45
publishMethod · 0.45

Tested by

no test coverage detected