From 7e28630f5ea63fb34c03ca7c8abee566da3cba9d Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Mon, 21 Mar 2011 14:36:30 -0700 Subject: [PATCH] Fix GH-820. CryptoStream.end shouldn't throw if not writable This matches the behavior of net.Socket --- lib/tls.js | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/lib/tls.js b/lib/tls.js index 3debbef389b..58481206131 100644 --- a/lib/tls.js +++ b/lib/tls.js @@ -168,25 +168,23 @@ CryptoStream.prototype.getCipher = function(err) { CryptoStream.prototype.end = function(d) { - if (!this.writable) { - throw new Error('CryptoStream is not writable'); + if (this.writable) { + if (this.pair._done) return; + + if (d) { + this.write(d); + } + + this._pending.push(END_OF_FILE); + this._pendingCallbacks.push(null); + + // If this is an encrypted stream then we need to disable further 'data' + // events. + + this.writable = false; + + this.pair._cycle(); } - - if (this.pair._done) return; - - if (d) { - this.write(d); - } - - this._pending.push(END_OF_FILE); - this._pendingCallbacks.push(null); - - // If this is an encrypted stream then we need to disable further 'data' - // events. - - this.writable = false; - - this.pair._cycle(); };