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

Method respond

lib/internal/http2/core.js:3005–3061  ·  view source on GitHub ↗
(headersParam, options)

Source from the content-addressed store, hash-verified

3003
3004 // Initiate a response on this Http2Stream
3005 respond(headersParam, options) {
3006 if (this.destroyed || this.closed)
3007 throw new ERR_HTTP2_INVALID_STREAM();
3008 if (this.headersSent)
3009 throw new ERR_HTTP2_HEADERS_SENT();
3010
3011 const state = this[kState];
3012
3013 assertIsObject(options, 'options');
3014 options = { ...options };
3015
3016 debugStreamObj(this, 'initiating response');
3017 this[kUpdateTimer]();
3018
3019 options.endStream = !!options.endStream;
3020
3021 let streamOptions = 0;
3022 if (options.endStream)
3023 streamOptions |= STREAM_OPTION_EMPTY_PAYLOAD;
3024
3025 if (options.waitForTrailers) {
3026 streamOptions |= STREAM_OPTION_GET_TRAILERS;
3027 state.flags |= STREAM_FLAGS_HAS_TRAILERS;
3028 }
3029
3030 const {
3031 headers,
3032 headersList,
3033 statusCode,
3034 } = prepareResponseHeaders(this, headersParam, options);
3035
3036 state.flags |= STREAM_FLAGS_HEADERS_SENT;
3037
3038 // Close the writable side if the endStream option is set or status
3039 // is one of known codes with no payload, or it's a head request
3040 if (!!options.endStream ||
3041 statusCode === HTTP_STATUS_NO_CONTENT ||
3042 statusCode === HTTP_STATUS_RESET_CONTENT ||
3043 statusCode === HTTP_STATUS_NOT_MODIFIED ||
3044 this.headRequest === true) {
3045 options.endStream = true;
3046 this.end();
3047 }
3048
3049 const ret = this[kHandle].respond(headersList, streamOptions);
3050 if (ret < 0) {
3051 this.destroy(new NghttpError(ret));
3052 } else if (onServerStreamFinishChannel.hasSubscribers) {
3053 // No point in running this if the respond() call above fails because
3054 // that would mean that it is an invalid call.
3055 onServerStreamFinishChannel.publish({
3056 stream: this,
3057 headers,
3058 flags: state.flags,
3059 });
3060 }
3061 }
3062

Callers 15

readNextFunction · 0.45
[kBeginSend]Method · 0.45
processRespondWithFDFunction · 0.45
core.jsFile · 0.45
pullMethod · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
onStreamFunction · 0.45
test-http2-pipe.jsFile · 0.45

Calls 5

debugStreamObjFunction · 0.85
prepareResponseHeadersFunction · 0.85
endMethod · 0.45
destroyMethod · 0.45
publishMethod · 0.45

Tested by

no test coverage detected