Comparing version 2.0.2 to 2.1.0
@@ -53,3 +53,3 @@ "use strict"; | ||
*/ | ||
const phin = (opts, cb, http) => { | ||
const phin = (opts, cb, injectedHttp) => { | ||
if (typeof(opts) !== "string" && !opts.hasOwnProperty("url")) { | ||
@@ -70,3 +70,3 @@ throw new Error("Missing url option from options for request method."); | ||
"method": "GET", | ||
"headers": { }, | ||
"headers": {}, | ||
"auth": (addr.auth || null) | ||
@@ -107,3 +107,3 @@ }; | ||
http = http || realHttp; | ||
const http = injectedHttp || realHttp; | ||
@@ -118,5 +118,5 @@ switch (addr.protocol.toLowerCase()) { | ||
default: | ||
const err = new Error("Invalid / unknown address protocol. Expected HTTP or HTTPS."); | ||
const err = new Error("Invalid / unknown URL protocol. Expected HTTP or HTTPS."); | ||
if (cb) { | ||
cb(err); | ||
cb(err, null); | ||
} | ||
@@ -128,3 +128,3 @@ return; | ||
if (cb) { | ||
cb(err); | ||
cb(err, null); | ||
} | ||
@@ -137,11 +137,11 @@ }); | ||
const contentType = options.headers["Content-Type"] || options.headers["content-type"]; | ||
if (contentType === "application/json") { | ||
postData = JSON.stringify(opts.data); | ||
} else if (contentType === "x/www-url-form-encoded") { | ||
if (contentType === "x/www-url-form-encoded") { | ||
postData = qs.stringify(opts.data); | ||
} else { | ||
const err2 = new Error("opts.data was passed in as an object, but the \"Content-Type\" (or \"content-type\") header was not \"application/json\" or \"x/www-url-form-encoded\"."); | ||
if (cb) { | ||
cb(err2); | ||
try { | ||
postData = JSON.stringify(opts.data); | ||
} | ||
catch (err) { | ||
cb(new Error("Couldn't stringify object. (Likely due to a circular reference.)"), null); | ||
} | ||
} | ||
@@ -148,0 +148,0 @@ } |
{ | ||
"name": "phin", | ||
"version": "2.0.2", | ||
"version": "2.1.0", | ||
"description": "Ultra-simple, lightweight, dependency-free Node.JS HTTP request client", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
1053557