(stream, code, rstStreamStatus = kSubmitRstStream)
| 2014 | const kForceRstStream = 2; |
| 2015 | |
| 2016 | function closeStream(stream, code, rstStreamStatus = kSubmitRstStream) { |
| 2017 | const type = stream[kSession][kType]; |
| 2018 | const state = stream[kState]; |
| 2019 | state.flags |= STREAM_FLAGS_CLOSED; |
| 2020 | state.rstCode = code; |
| 2021 | |
| 2022 | // Clear timeout and remove timeout listeners |
| 2023 | stream.setTimeout(0); |
| 2024 | stream.removeAllListeners('timeout'); |
| 2025 | |
| 2026 | const { ending } = stream._writableState; |
| 2027 | |
| 2028 | if (!ending) { |
| 2029 | // If the writable side of the Http2Stream is still open, emit the |
| 2030 | // 'aborted' event and set the aborted flag. |
| 2031 | if (!stream.aborted) { |
| 2032 | state.flags |= STREAM_FLAGS_ABORTED; |
| 2033 | stream.emit('aborted'); |
| 2034 | } |
| 2035 | |
| 2036 | // Close the writable side. |
| 2037 | stream.end(); |
| 2038 | } |
| 2039 | |
| 2040 | if (rstStreamStatus !== kNoRstStream) { |
| 2041 | const finishFn = finishCloseStream.bind(stream, code); |
| 2042 | if (!ending || stream.writableFinished || code !== NGHTTP2_NO_ERROR || |
| 2043 | rstStreamStatus === kForceRstStream) |
| 2044 | finishFn(); |
| 2045 | else |
| 2046 | stream.once('finish', finishFn); |
| 2047 | } |
| 2048 | |
| 2049 | if (type === NGHTTP2_SESSION_CLIENT) { |
| 2050 | if (onClientStreamCloseChannel.hasSubscribers) { |
| 2051 | onClientStreamCloseChannel.publish({ stream }); |
| 2052 | } |
| 2053 | } else if (onServerStreamCloseChannel.hasSubscribers) { |
| 2054 | onServerStreamCloseChannel.publish({ stream }); |
| 2055 | } |
| 2056 | } |
| 2057 | |
| 2058 | function finishCloseStream(code) { |
| 2059 | const rstStreamFn = submitRstStream.bind(this, code); |
no test coverage detected
searching dependent graphs…