lib: turn on strict mode
[platform/upstream/nodejs.git] / lib / _http_outgoing.js
index bec9a3c..cef135c 100644 (file)
@@ -19,6 +19,8 @@
 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
 // USE OR OTHER DEALINGS IN THE SOFTWARE.
 
+'use strict';
+
 var assert = require('assert').ok;
 var Stream = require('stream');
 var timers = require('timers');
@@ -82,9 +84,13 @@ function OutgoingMessage() {
 
   this.finished = false;
   this._hangupClose = false;
+  this._headerSent = false;
 
   this.socket = null;
   this.connection = null;
+  this._header = null;
+  this._headers = null;
+  this._headerNames = {};
 }
 util.inherits(OutgoingMessage, Stream);
 
@@ -323,23 +329,22 @@ function storeHeader(self, state, field, value) {
 
 
 OutgoingMessage.prototype.setHeader = function(name, value) {
-  if (arguments.length < 2) {
-    throw new Error('`name` and `value` are required for setHeader().');
-  }
-
-  if (this._header) {
+  if (typeof name !== 'string')
+    throw new TypeError('"name" should be a string');
+  if (value === undefined)
+    throw new Error('"name" and "value" are required for setHeader().');
+  if (this._header)
     throw new Error('Can\'t set headers after they are sent.');
-  }
+
+  if (this._headers === null)
+    this._headers = {};
 
   var key = name.toLowerCase();
-  this._headers = this._headers || {};
-  this._headerNames = this._headerNames || {};
   this._headers[key] = value;
   this._headerNames[key] = name;
 
-  if (automaticHeaders[key]) {
+  if (automaticHeaders[key])
     this._removedHeader[key] = false;
-  }
 };
 
 
@@ -387,6 +392,7 @@ OutgoingMessage.prototype._renderHeaders = function() {
 
   var headers = {};
   var keys = Object.keys(this._headers);
+
   for (var i = 0, l = keys.length; i < l; i++) {
     var key = keys[i];
     headers[this._headerNames[key]] = this._headers[key];