(session, options, fd, headers, streamOptions, err, stat)
| 2797 | } |
| 2798 | |
| 2799 | function doSendFileFD(session, options, fd, headers, streamOptions, err, stat) { |
| 2800 | const onError = options.onError; |
| 2801 | |
| 2802 | if (err) { |
| 2803 | tryClose(fd); |
| 2804 | if (onError) |
| 2805 | onError(err); |
| 2806 | else |
| 2807 | this.destroy(err); |
| 2808 | return; |
| 2809 | } |
| 2810 | |
| 2811 | if (!stat.isFile()) { |
| 2812 | const isDirectory = stat.isDirectory(); |
| 2813 | if (options.offset !== undefined || options.offset > 0 || |
| 2814 | options.length !== undefined || options.length >= 0 || |
| 2815 | isDirectory) { |
| 2816 | const err = isDirectory ? |
| 2817 | new ERR_HTTP2_SEND_FILE() : new ERR_HTTP2_SEND_FILE_NOSEEK(); |
| 2818 | tryClose(fd); |
| 2819 | if (onError) |
| 2820 | onError(err); |
| 2821 | else |
| 2822 | this.destroy(err); |
| 2823 | return; |
| 2824 | } |
| 2825 | |
| 2826 | options.offset = -1; |
| 2827 | options.length = -1; |
| 2828 | } |
| 2829 | |
| 2830 | if (this.destroyed || this.closed) { |
| 2831 | tryClose(fd); |
| 2832 | this.destroy(new ERR_HTTP2_INVALID_STREAM()); |
| 2833 | return; |
| 2834 | } |
| 2835 | |
| 2836 | const statOptions = { |
| 2837 | offset: options.offset !== undefined ? options.offset : 0, |
| 2838 | length: options.length !== undefined ? options.length : -1, |
| 2839 | }; |
| 2840 | |
| 2841 | // options.statCheck is a user-provided function that can be used to |
| 2842 | // verify stat values, override or set headers, or even cancel the |
| 2843 | // response operation. If statCheck explicitly returns false, the |
| 2844 | // response is canceled. The user code may also send a separate type |
| 2845 | // of response so check again for the HEADERS_SENT flag |
| 2846 | if ((typeof options.statCheck === 'function' && |
| 2847 | options.statCheck.call(this, stat, headers) === false) || |
| 2848 | (this[kState].flags & STREAM_FLAGS_HEADERS_SENT)) { |
| 2849 | tryClose(fd); |
| 2850 | return; |
| 2851 | } |
| 2852 | |
| 2853 | if (stat.isFile()) { |
| 2854 | statOptions.length = |
| 2855 | statOptions.length < 0 ? stat.size - (+statOptions.offset) : |
| 2856 | MathMin(stat.size - (+statOptions.offset), |
nothing calls this directly
no test coverage detected
searching dependent graphs…