Comparing version 0.5.6 to 0.5.7
{ | ||
"name": "popsicle", | ||
"version": "0.5.6", | ||
"version": "0.5.7", | ||
"description": "Simple HTTP requests for node and the browser", | ||
@@ -5,0 +5,0 @@ "main": "popsicle.js", |
@@ -128,2 +128,12 @@ /* global define */ | ||
/** | ||
* Check if an object is actually a stream. | ||
* | ||
* @param {Object} obj | ||
* @return {Boolean} | ||
*/ | ||
function isStream (obj) { | ||
return typeof obj.pipe === 'function' | ||
} | ||
/** | ||
* Create a timeout error instance. | ||
@@ -456,5 +466,19 @@ * | ||
// Set the `Content-Type` headers, which contains a boundary. | ||
// Manually set the `Content-Length` and `Content-Type` headers from the | ||
// form data object because we need to handle boundaries and streams. | ||
if (req.body instanceof FormData) { | ||
req.set(req.body.getHeaders()) | ||
req.set('Content-Type', 'multipart/form-data; boundary=' + req.body.getBoundary()) | ||
// Asynchronously compute the content length. | ||
return new Promise(function (resolve, reject) { | ||
req.body.getLength(function (err, length) { | ||
if (err) { | ||
req.set('Transfer-Encoding', 'chunked') | ||
} else { | ||
req.set('Content-Length', length) | ||
} | ||
return resolve() | ||
}) | ||
}) | ||
} | ||
@@ -465,2 +489,3 @@ | ||
// Attempt to manually compute the content length. | ||
if (body && !req.get('Content-Length')) { | ||
@@ -473,3 +498,3 @@ if (Array.isArray(body)) { | ||
length = Buffer.byteLength(body) | ||
} else if (Buffer.isBuffer(body)) { | ||
} else { | ||
length = body.length | ||
@@ -480,11 +505,17 @@ } | ||
req.set('Content-Length', length) | ||
} else if (isStream(body)) { | ||
req.set('Transfer-Encoding', 'chunked') | ||
} else { | ||
return Promise.reject(req.error('Argument error, `options.body`')) | ||
} | ||
} | ||
} 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') | ||
} | ||
return | ||
} | ||
// 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') | ||
} | ||
} | ||
@@ -503,5 +534,3 @@ | ||
req._error = undefined | ||
req._raw = undefined | ||
req.body = undefined | ||
@@ -1323,3 +1352,3 @@ } | ||
if (body) { | ||
if (typeof body.pipe === 'function') { | ||
if (isStream(body)) { | ||
body.pipe(requestProxy) | ||
@@ -1326,0 +1355,0 @@ } else { |
@@ -72,3 +72,3 @@ # ![Popsicle](https://cdn.rawgit.com/blakeembrey/popsicle/master/logo.svg) | ||
* **timeout** The number of milliseconds before cancelling the request (default: `Infinity`) | ||
* **parse** Skip automatic response parsing (default: `true`) | ||
* **parse** Disable automatic response parsing (default: `true`) | ||
@@ -81,5 +81,5 @@ **Node only** | ||
* **rejectUnauthorized** Reject invalid SSL certificates (default: `true`) | ||
* **stream** Stream the HTTP response body (default: `false`, disables `parse`) | ||
* **raw** Return the raw stream without unzipping (default: `false`, disables `parse`) | ||
* **encoding** Specify the response body format when not streaming (default: `string`, allowed: `string`, `buffer`, `array`, `uint8`, disables `parse`) | ||
* **stream** Stream the HTTP response body (default: `false`, disables `parse` when enabled) | ||
* **raw** Return the raw stream without unzipping (default: `false`, disables `parse` when enabled) | ||
* **encoding** Specify the response body format when not streaming (default: `string`, allowed: `string`, `buffer`, `array`, `uint8`, disables `parse` when not `string`) | ||
@@ -86,0 +86,0 @@ **Browser only** |
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
53125
1342