(chunk, encoding, cb)
| 817 | } |
| 818 | |
| 819 | end(chunk, encoding, cb) { |
| 820 | const stream = this[kStream]; |
| 821 | const state = this[kState]; |
| 822 | |
| 823 | if (typeof chunk === 'function') { |
| 824 | cb = chunk; |
| 825 | chunk = null; |
| 826 | } else if (typeof encoding === 'function') { |
| 827 | cb = encoding; |
| 828 | encoding = 'utf8'; |
| 829 | } |
| 830 | |
| 831 | if ((state.closed || state.ending) && |
| 832 | state.headRequest === stream.headRequest) { |
| 833 | if (typeof cb === 'function') { |
| 834 | process.nextTick(cb); |
| 835 | } |
| 836 | return this; |
| 837 | } |
| 838 | |
| 839 | if (chunk !== null && chunk !== undefined) |
| 840 | this.write(chunk, encoding); |
| 841 | |
| 842 | state.headRequest = stream.headRequest; |
| 843 | state.ending = true; |
| 844 | |
| 845 | if (typeof cb === 'function') { |
| 846 | if (stream.writableEnded) |
| 847 | this.once('finish', cb); |
| 848 | else |
| 849 | stream.once('finish', cb); |
| 850 | } |
| 851 | |
| 852 | if (!stream.headersSent) |
| 853 | this.writeHead(this[kState].statusCode); |
| 854 | |
| 855 | if (this[kState].closed || stream.destroyed) |
| 856 | onStreamCloseResponse.call(stream); |
| 857 | else |
| 858 | stream.end(); |
| 859 | |
| 860 | return this; |
| 861 | } |
| 862 | |
| 863 | destroy(err) { |
| 864 | if (this[kState].destroyed) |
no test coverage detected