// 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');
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);
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;
- }
};
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];