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

Method respondWithFD

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

Source from the content-addressed store, hash-verified

3067 // mechanism is not able to read from the fd, then the stream will be
3068 // reset with an error code.
3069 respondWithFD(fd, headersParam, options) {
3070 if (this.destroyed || this.closed)
3071 throw new ERR_HTTP2_INVALID_STREAM();
3072 if (this.headersSent)
3073 throw new ERR_HTTP2_HEADERS_SENT();
3074
3075 const session = this[kSession];
3076
3077 assertIsObject(options, 'options');
3078 options = { ...options };
3079
3080 if (options.offset !== undefined && typeof options.offset !== 'number')
3081 throw new ERR_INVALID_ARG_VALUE('options.offset', options.offset);
3082
3083 if (options.length !== undefined && typeof options.length !== 'number')
3084 throw new ERR_INVALID_ARG_VALUE('options.length', options.length);
3085
3086 if (options.statCheck !== undefined &&
3087 typeof options.statCheck !== 'function') {
3088 throw new ERR_INVALID_ARG_VALUE('options.statCheck', options.statCheck);
3089 }
3090
3091 let streamOptions = 0;
3092 if (options.waitForTrailers) {
3093 streamOptions |= STREAM_OPTION_GET_TRAILERS;
3094 this[kState].flags |= STREAM_FLAGS_HAS_TRAILERS;
3095 }
3096
3097 if (fd instanceof fsPromisesInternal.FileHandle)
3098 fd = fd.fd;
3099 else if (typeof fd !== 'number')
3100 throw new ERR_INVALID_ARG_TYPE('fd', ['number', 'FileHandle'], fd);
3101
3102 debugStreamObj(this, 'initiating response from fd');
3103 this[kUpdateTimer]();
3104 this.ownsFd = false;
3105
3106 const {
3107 headers,
3108 statusCode,
3109 } = prepareResponseHeadersObject(headersParam, options);
3110
3111 // Payload/DATA frames are not permitted in these cases
3112 if (statusCode === HTTP_STATUS_NO_CONTENT ||
3113 statusCode === HTTP_STATUS_RESET_CONTENT ||
3114 statusCode === HTTP_STATUS_NOT_MODIFIED ||
3115 this.headRequest) {
3116 throw new ERR_HTTP2_PAYLOAD_FORBIDDEN(statusCode);
3117 }
3118
3119 if (options.statCheck !== undefined) {
3120 fs.fstat(fd,
3121 doSendFD.bind(this, session, options, fd, headers, streamOptions));
3122 return;
3123 }
3124
3125 processRespondWithFD(this, fd, headers,
3126 options.offset,

Calls 5

debugStreamObjFunction · 0.85
processRespondWithFDFunction · 0.85
fstatMethod · 0.80
bindMethod · 0.45

Tested by

no test coverage detected