Comparing version 0.1.6 to 0.2.0
32
index.js
@@ -39,6 +39,12 @@ var http = require("http"), | ||
this.response = null; | ||
this._body = ""; | ||
this._body = new Buffer(0); | ||
if(typeof options.uri !== "object") options.uri = url.parse(options.uri); | ||
if(typeof options.uri === "string"){ | ||
options.uri = url.parse(options.uri); | ||
} else if(typeof options.uri !== "object"){ | ||
this.emit("error", Error("No URI specified!")); | ||
return; | ||
} | ||
//fix for node < 0.5 | ||
@@ -51,7 +57,2 @@ if( !("path" in options.uri) ) options.uri.path = options.uri.pathname; | ||
if(typeof options.uri !== "object"){ | ||
this.emit("error", Error("No URI specified!")); | ||
return; | ||
} | ||
if( !(options.uri.protocol in protocols) ){ | ||
@@ -108,2 +109,3 @@ this.emit("error", Error("Unknown protocol: " + options.uri.protocol)); | ||
if(scope._cb) scope._cb(err); | ||
scope._cb = null; //remove the cb | ||
}); | ||
@@ -113,8 +115,12 @@ | ||
scope._ended = true; | ||
if(scope._cb) scope._cb(null, scope.response, scope._body); | ||
}); | ||
this.on("data", function(chunk){ | ||
scope._body += chunk; | ||
}); | ||
if(this._cb){ | ||
this.on("data", function(chunk){ | ||
scope._body = Buffer.concat([scope._body, chunk]); | ||
}); | ||
this.on("end", function(){ | ||
scope._cb(null, scope.response, scope._body); | ||
}); | ||
} | ||
@@ -234,6 +240,2 @@ this.on("redirect", function(location){ | ||
}; | ||
Request.prototype.then = function(cb){ | ||
//for promise-like behavior | ||
this._cb = cb; | ||
}; | ||
Request.prototype.abort = function(){ | ||
@@ -240,0 +242,0 @@ this._request.abort(); |
{ | ||
"name": "minreq", | ||
"version": "0.1.6", | ||
"version": "0.2.0", | ||
"description": "minimalistic request library", | ||
@@ -5,0 +5,0 @@ "author": "Felix Boehm <me@feedic.com>", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No License Found
License(Experimental) License information could not be found.
Found 1 instance in 1 package
9593
4
0
221