Fix GH-820. CryptoStream.end shouldn't throw if not writable
authorRyan Dahl <ry@tinyclouds.org>
Mon, 21 Mar 2011 21:36:30 +0000 (14:36 -0700)
committerRyan Dahl <ry@tinyclouds.org>
Mon, 21 Mar 2011 21:36:49 +0000 (14:36 -0700)
This matches the behavior of net.Socket

lib/tls.js

index 3debbef389b710f4d4fca6ba68710a1a4fad775a..584812061319c34544eb0944d77646712937c155 100644 (file)
@@ -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.pair._done) return;
+  if (this.writable) {
+    if (this.pair._done) return;
 
-  if (d) {
-    this.write(d);
-  }
+    if (d) {
+      this.write(d);
+    }
 
-  this._pending.push(END_OF_FILE);
-  this._pendingCallbacks.push(null);
+    this._pending.push(END_OF_FILE);
+    this._pendingCallbacks.push(null);
 
-  // If this is an encrypted stream then we need to disable further 'data'
-  // events.
+    // If this is an encrypted stream then we need to disable further 'data'
+    // events.
 
-  this.writable = false;
+    this.writable = false;
 
-  this.pair._cycle();
+    this.pair._cycle();
+  }
 };