Comparing version 0.3.3 to 0.3.4
{ | ||
"name": "popsicle", | ||
"main": "popsicle.js", | ||
"version": "0.3.3", | ||
"version": "0.3.4", | ||
"homepage": "https://github.com/blakeembrey/popsicle", | ||
@@ -6,0 +6,0 @@ "authors": [ |
{ | ||
"name": "popsicle", | ||
"version": "0.3.3", | ||
"version": "0.3.4", | ||
"description": "Simple HTTP requests for node and the browser", | ||
@@ -5,0 +5,0 @@ "main": "popsicle.js", |
@@ -110,2 +110,12 @@ (function () { | ||
/** | ||
* Check if an object is actually an object (not a primitive type). | ||
* | ||
* @param {Object} obj | ||
* @return {Boolean} | ||
*/ | ||
function isObject (obj) { | ||
return Object(obj) === obj; | ||
} | ||
/** | ||
* Create a stream error instance. | ||
@@ -232,6 +242,2 @@ * | ||
function stringifyQuery (obj) { | ||
if (Object(obj) !== obj) { | ||
return String(obj == null ? '' : obj); | ||
} | ||
var params = []; | ||
@@ -259,9 +265,13 @@ | ||
* @param {String} qs | ||
* @param {Object} [obj] | ||
* @return {Object} | ||
*/ | ||
function parseQuery (qs, obj) { | ||
obj = obj || {}; | ||
qs = qs.split(FORM_SEP); | ||
function parseQuery (qs) { | ||
// Unable to parse empty values. | ||
if (qs == null || qs === '') { | ||
return {}; | ||
} | ||
qs = String(qs).split(FORM_SEP); | ||
var obj = {}; | ||
var maxKeys = 1000; | ||
@@ -350,3 +360,3 @@ var len = qs.length > maxKeys ? maxKeys : qs.length; | ||
// Convert primitives types into strings. | ||
if (Object(body) !== body) { | ||
if (!isObject(body)) { | ||
request.body = body == null ? null : String(body); | ||
@@ -652,2 +662,4 @@ | ||
var query = options.query; | ||
// Request options. | ||
@@ -657,3 +669,3 @@ this.body = options.body; | ||
this.method = (options.method || 'GET').toUpperCase(); | ||
this.query = assign({}, options.query); | ||
this.query = assign({}, isObject(query) ? query : parseQuery(query)); | ||
this.timeout = options.timeout; | ||
@@ -678,4 +690,6 @@ this.withCredentials = options.withCredentials === true; | ||
if (queryIndex > -1) { | ||
this.url = options.url.substr(0, queryIndex); | ||
this.query = parseQuery(options.url.substr(queryIndex + 1), this.query); | ||
this.url = options.url.substr(0, queryIndex); | ||
// Copy url query parameters onto query object. | ||
assign(this.query, parseQuery(options.url.substr(queryIndex + 1))); | ||
} | ||
@@ -1148,5 +1162,6 @@ } | ||
// TODO: Emit a stream error if already aborted. | ||
this._stream = this._request = request(requestOptions(this)); | ||
// TODO: Catch stream errors and coerce to popsicle errors. | ||
var req = this._stream = request(requestOptions(this)); | ||
trackRequestProgress(this); | ||
trackRequestProgress(this, req); | ||
} | ||
@@ -1153,0 +1168,0 @@ |
@@ -266,2 +266,17 @@ var isNode = typeof window === 'undefined'; | ||
}); | ||
it('should accept query as a string', function () { | ||
var req = popsicle({ | ||
url: REMOTE_URL + '/echo/query', | ||
query: 'query=true' | ||
}); | ||
expect(req.url).to.equal(REMOTE_URL + '/echo/query'); | ||
expect(req.query).to.deep.equal({ query: 'true' }); | ||
return req | ||
.then(function (res) { | ||
expect(res.body).to.deep.equal({ query: 'true' }); | ||
}); | ||
}); | ||
}); | ||
@@ -268,0 +283,0 @@ |
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
70636
1904