Comparing version 0.1.4 to 0.1.5
30
index.js
@@ -202,2 +202,8 @@ var http = require("http"), | ||
if(this._options.headers){ | ||
for(var header in this._options.headers){ | ||
this._request.setHeader(header, this._options.headers[header]); | ||
} | ||
} | ||
if(!("timeout" in options) || options.timeout){ | ||
@@ -234,3 +240,27 @@ this._reqTimeout = setTimeout(function(){ | ||
}; | ||
Request.prototype.setHeader = function(name, value){ | ||
if(arguments.length < 2) throw Error("wrong number of arguments"); | ||
if(this._request){ | ||
return this._request.setHeader(name, value); | ||
} | ||
if(typeof this._options.headers !== "object"){ | ||
this._options.headers = {__proto__: null}; | ||
} | ||
this._options.headers[name.toLowerCase()] = value; | ||
}; | ||
Request.prototype.getHeader = function(name){ | ||
if(arguments.length < 1) throw Error("wrong number of arguments"); | ||
if(this._request){ | ||
return this._request.getHeader(name); | ||
} | ||
return this._options.headers && this._options.headers[name.toLowerCase()]; | ||
}; | ||
Request.prototype.removeHeader = function(name){ | ||
if(arguments.length < 1) throw Error("wrong number of arguments"); | ||
if(this._request){ | ||
return this._request.removeHeader(name); | ||
} | ||
return this._options.headers && delete this._options.headers[name.toLowerCase()]; | ||
}; | ||
module.exports.Request = Request; |
{ | ||
"name": "minreq", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "minimalistic request library", | ||
@@ -5,0 +5,0 @@ "author": "Felix Boehm <me@feedic.com>", |
8215
218