Comparing version 0.5.2 to 0.5.3
{ | ||
"name": "popsicle", | ||
"version": "0.5.2", | ||
"version": "0.5.3", | ||
"description": "Simple HTTP requests for node and the browser", | ||
@@ -5,0 +5,0 @@ "main": "popsicle.js", |
@@ -422,19 +422,40 @@ /* global define */ | ||
// Specify a default user agent in node. | ||
if (!req.get('User-Agent')) { | ||
req.set('User-Agent', 'https://github.com/blakeembrey/popsicle') | ||
} | ||
if (isNode) { | ||
// Specify a default user agent in node. | ||
if (!req.get('User-Agent')) { | ||
req.set('User-Agent', 'https://github.com/blakeembrey/popsicle') | ||
} | ||
// Accept zipped responses. | ||
if (!req.get('Accept-Encoding')) { | ||
req.set('Accept-Encoding', 'gzip,deflate') | ||
} | ||
// Accept zipped responses. | ||
if (!req.get('Accept-Encoding')) { | ||
req.set('Accept-Encoding', 'gzip,deflate') | ||
} | ||
// Remove the `Content-Type` header from form data requests. The node | ||
// `request` module supports `form-data` to automatically add headers, | ||
// and the browser will set it on `xhr.send` (only when it doesn't exist). | ||
if (req.body instanceof FormData) { | ||
if (isNode) { | ||
// Set the `Content-Type` headers, which contains a boundary. | ||
if (req.body instanceof FormData) { | ||
req.set(req.body.getHeaders()) | ||
} else { | ||
} | ||
var length = 0 | ||
var body = req.body | ||
if (body && !req.get('Content-Length')) { | ||
if (Array.isArray(body)) { | ||
for (var i = 0; i < body.length; i++) { | ||
length += body[i].length | ||
} | ||
} else if (typeof body === 'string') { | ||
length = Buffer.byteLength(body) | ||
} else if (Buffer.isBuffer(body)) { | ||
length = body.length | ||
} | ||
if (length) { | ||
req.set('Content-Length', length) | ||
} | ||
} | ||
} else { | ||
// Remove the `Content-Type` header from form data requests. Browsers | ||
// will only fill it automatically when it doesn't exist. | ||
if (req.body instanceof FormData) { | ||
req.remove('Content-Type') | ||
@@ -898,9 +919,5 @@ } | ||
if (isNode) { | ||
this.before(contentLength) | ||
if (this.jar) { | ||
this.before(getCookieJar) | ||
this.after(setCookieJar) | ||
} | ||
if (this.jar && isNode) { | ||
this.before(getCookieJar) | ||
this.after(setCookieJar) | ||
} | ||
@@ -1073,31 +1090,2 @@ | ||
/** | ||
* Set the default content length. | ||
* | ||
* @param {Request} req | ||
*/ | ||
var contentLength = function (req) { | ||
var length = 0 | ||
var body = req.body | ||
if (body && !req.get('Content-Length')) { | ||
if (!Buffer.isBuffer(body)) { | ||
if (Array.isArray(body)) { | ||
for (var i = 0; i < body.length; i++) { | ||
length += body[i].length | ||
} | ||
} else { | ||
body = new Buffer(body) | ||
length = body.length | ||
} | ||
} else { | ||
length = body.length | ||
} | ||
if (length) { | ||
req.set('Content-Length', length) | ||
} | ||
} | ||
} | ||
/** | ||
* Read cookies from the cookie jar. | ||
@@ -1104,0 +1092,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
50911
1280