Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

request-promise

Package Overview
Dependencies
Maintainers
5
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

request-promise - npm Package Compare versions

Comparing version 0.4.2 to 0.4.3

32

lib/rp.js

@@ -5,3 +5,9 @@ 'use strict';

CapturedTrace = require('./bluebird-captured-trace-fresh.js'),
_ = require('lodash'),
assign = require('lodash/object/assign'),
forEach = require('lodash/collection/forEach'),
isFunction = require('lodash/lang/isFunction'),
isPlainObject = require('lodash/lang/isPlainObject'),
isString = require('lodash/lang/isString'),
isUndefined = require('lodash/lang/isUndefined'),
keys = require('lodash/object/keys'),
chalk = require('chalk'),

@@ -15,3 +21,3 @@ errors = require('./errors.js');

function clearCache() {
_.forEach(_.keys(require.cache), function (key) {
forEach(keys(require.cache), function (key) {
delete require.cache[key];

@@ -21,3 +27,3 @@ });

var temp = _.assign({}, require.cache);
var temp = assign({}, require.cache);
clearCache();

@@ -28,3 +34,3 @@

clearCache();
_.assign(require.cache, temp);
assign(require.cache, temp);

@@ -43,3 +49,3 @@ return freshRequest;

if (_.isFunction(self._rp_callbackOrig)) {
if (isFunction(self._rp_callbackOrig)) {
try {

@@ -55,3 +61,3 @@ self._rp_callbackOrig.apply(self, arguments);

self._rp_reject(_.assign(new errors.RequestError(err), {
self._rp_reject(assign(new errors.RequestError(err), {
error: err,

@@ -64,3 +70,3 @@ options: self._rp_options,

self._rp_reject(_.assign(new errors.StatusCodeError(response.statusCode, body), {
self._rp_reject(assign(new errors.StatusCodeError(response.statusCode, body), {
error: body,

@@ -72,3 +78,3 @@ options: self._rp_options,

} else {
if (_.isFunction(self._rp_options.transform)) {
if (isFunction(self._rp_options.transform)) {
try {

@@ -91,3 +97,3 @@ self._rp_resolve(self._rp_options.transform(body, response));

// Mimic original behavior of errors emitted by request with no error listener registered
if (err && _.isFunction(self._rp_callbackOrig) === false && self._rp_promise_in_use !== true && self.listeners('error').length === 1) {
if (err && isFunction(self._rp_callbackOrig) === false && self._rp_promise_in_use !== true && self.listeners('error').length === 1) {
throw err;

@@ -105,3 +111,3 @@ }

// Init may be called again - currently in case of redirects
if (_.isPlainObject(options) && self._callback === undefined && self._rp_promise === undefined) {
if (isPlainObject(options) && self._callback === undefined && self._rp_promise === undefined) {

@@ -117,3 +123,3 @@ self._rp_promise = new Bluebird(function (resolve, reject) {

if (_.isString(options.method)) {
if (isString(options.method)) {
options.method = options.method.toUpperCase();

@@ -142,4 +148,4 @@ }

/* istanbul ignore if */
if (!_.isUndefined(request.Request.prototype[exposeAs])) {
console.error(chalk.bold.bgRed('[Request-Promise] Unable to expose method "' + exposeAs + '". It is already implemented by Request. Please visit https://github.com/tyabonil/request-promise/wiki/Troubleshooting'));
if (!isUndefined(request.Request.prototype[exposeAs])) {
console.error(chalk.bold.bgRed('[Request-Promise] Unable to expose method "' + exposeAs + '". It is already implemented by Request. Please visit https://github.com/request/request-promise/wiki/Troubleshooting'));
return;

@@ -146,0 +152,0 @@ }

{
"name": "request-promise",
"version": "0.4.2",
"version": "0.4.3",
"description": "The world-famous HTTP client 'Request' now Promises/A+ compliant. Powered by Bluebird.",

@@ -14,5 +14,5 @@ "keywords": [

],
"homepage": "https://github.com/tyabonil/request-promise",
"homepage": "https://github.com/request/request-promise",
"bugs": {
"url": "https://github.com/tyabonil/request-promise/issues"
"url": "https://github.com/request/request-promise/issues"
},

@@ -27,3 +27,3 @@ "license": "MIT",

"type": "git",
"url": "https://github.com/tyabonil/request-promise.git"
"url": "https://github.com/request/request-promise.git"
},

@@ -35,4 +35,4 @@ "scripts": {

"bluebird": "^2.3",
"chalk": "1.0.x",
"lodash": "3.6.x",
"chalk": "^1.1.0",
"lodash": "^3.10.0",
"request": "^2.34"

@@ -39,0 +39,0 @@ },

@@ -16,3 +16,3 @@ <a href="http://promisesaplus.com/">

[![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/tyabonil/request-promise?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [![Build Status](https://travis-ci.org/tyabonil/request-promise.svg?branch=master)](https://travis-ci.org/tyabonil/request-promise) [![Coverage Status](http://img.shields.io/badge/coverage-far%20beyond%20100%25-brightgreen.svg)](#can-i-trust-this-module) [![Dependency Status](https://david-dm.org/tyabonil/request-promise.svg)](https://david-dm.org/tyabonil/request-promise)
[![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/request/request-promise?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [![Build Status](https://travis-ci.org/request/request-promise.svg?branch=master)](https://travis-ci.org/request/request-promise) [![Coverage Status](http://img.shields.io/badge/coverage-far%20beyond%20100%25-brightgreen.svg)](#can-i-trust-this-module) [![Dependency Status](https://david-dm.org/request/request-promise.svg)](https://david-dm.org/request/request-promise)

@@ -27,3 +27,3 @@ The world-famous HTTP client "Request" now Promises/A+ compliant. Powered by Bluebird.

Request-Promise is perfect for replacing callbacks with promises. However, if you want to pipe large amounts of data we recommend using Request for the reason [described below](#can-i-trust-this-module). Both Request and Request-Promise can be required side by side.
Request-Promise is perfect for replacing callbacks with promises. However, if you want to pipe large quantities of data we recommend using Request for the reason [described below](#can-i-trust-this-module). Both Request and Request-Promise can be required side by side.

@@ -382,3 +382,3 @@ See the [migration instructions](#migrating-from-02x-to-03x) for important changes between 0.2.x and 0.3.x. Issues and pull requests for 0.2.x are still welcome.

However, there is one important design detail: Request-Promise passes a callback to each Request call which it uses to resolve or reject the promise. The callback is also registered if you don't use the promise features in a certain request. E.g. you may only use streaming: `rp(...).pipe(...)` As a result, [additional code](https://github.com/request/request/blob/master/request.js#L1166-L1213) is executed that buffers the streamed data and passes it as the response body to the "complete" event. If you stream large quantities of data the buffer grows big and that has an impact on your memory footprint. In these cases you can just `var request = require('request');` and use `request` for streaming large quantities of data.
However, there is one important design detail: Request-Promise passes a callback to each Request call which it uses to resolve or reject the promise. The callback is also registered if you don't use the promise features in a certain request. E.g. you may only use streaming: `rp(...).pipe(...)` As a result, [additional code](https://github.com/request/request/blob/master/request.js#L1010-L1059) is executed that buffers the streamed data and passes it as the response body to the "complete" event. If you stream [large quantities of data](https://github.com/request/request-promise/issues/53) the buffer grows big and that has an impact on your memory footprint. In these cases you can just `var request = require('request');` and use `request` for streaming large quantities of data.

@@ -403,2 +403,6 @@ ## Contributing

- v0.4.3 (2015-07-27)
- Reduced overhead by just requiring used lodash functions instead of the whole lodash library
*(Thanks to @luanmuniz for [pull request #54](https://github.com/request/request-promise/pull/54))*
- Updated dependencies
- v0.4.2 (2015-04-12)

@@ -408,6 +412,6 @@ - Updated dependencies

- Improved Error types to work in browsers without v8 engine
*(Thanks to @nodiis for [pull request #40](https://github.com/tyabonil/request-promise/pull/40))*
*(Thanks to @nodiis for [pull request #40](https://github.com/request/request-promise/pull/40))*
- v0.4.0 (2015-02-08)
- Introduced Error types used for the reject reasons (See last part [this section](#rejected-promises-and-the-simple-option))
*(Thanks to @jakecraige for starting the discussion in [issue #38](https://github.com/tyabonil/request-promise/issues/38))*
*(Thanks to @jakecraige for starting the discussion in [issue #38](https://github.com/request/request-promise/issues/38))*
- **Minor Braking Change:** The reject reason objects became actual Error objects. However, `typeof reason === 'object'` still holds true and the error objects have the same properties as the previous reason objects. If the reject handler only accesses the properties on the reason object - which is usually the case - no migration is required.

@@ -417,9 +421,9 @@ - [Added io.js](#support-for-iojs) and node.js 0.12 to the Travis CI build

- Fixed handling possibly unhandled rejections to work with the latest version of Bluebird
*(Thanks to @slang800 for reporting this in [issue #36](https://github.com/tyabonil/request-promise/issues/36))*
*(Thanks to @slang800 for reporting this in [issue #36](https://github.com/request/request-promise/issues/36))*
- v0.3.2 (2014-11-17)
- Exposed `.finally(...)` to allow using it as the first method in the promise chain
*(Thanks to @hjpbarcelos for his [pull request #28](https://github.com/tyabonil/request-promise/pull/28))*
*(Thanks to @hjpbarcelos for his [pull request #28](https://github.com/request/request-promise/pull/28))*
- v0.3.1 (2014-11-11)
- Added the `.promise()` method for advanced Bluebird API usage
*(Thanks to @devo-tox for his feedback in [issue #27](https://github.com/tyabonil/request-promise/issues/27))*
*(Thanks to @devo-tox for his feedback in [issue #27](https://github.com/request/request-promise/issues/27))*
- v0.3.0 (2014-11-10)

@@ -432,11 +436,11 @@ - Carefully rewritten from scratch to make Request-Promise a [drop-in replacement for Request](#request-promise-is-a-drop-in-replacement-for-request)

- Fixed http method shortcuts like `rp.get(...)` when used with passing an options object
*(Thanks to @hjpbarcelos for reporting this in [issue #29](https://github.com/tyabonil/request-promise/issues/29))*
*(Thanks to @hjpbarcelos for reporting this in [issue #29](https://github.com/request/request-promise/issues/29))*
- v0.2.6 (2014-11-09)
- When calling `rp.defaults(...)` the passed `resolveWithFullResponse` option is not always overwritten by the default anymore.
- The function passed as the `transform` option now also gets the full response as the second parameter. The new signature is: `function (body, response) { }`
*(Thanks to @khankuan for his feedback in [issue #24](https://github.com/tyabonil/request-promise/issues/24))*
*(Thanks to @khankuan for his feedback in [issue #24](https://github.com/request/request-promise/issues/24))*
- If the transform function throws an exception it is caught and the promise is rejected with it.
- v0.2.5 (2014-11-06)
- The Request instance which is wrapped by Request-Promise is exposed as `rp.request`.
*(Thanks to @hjpbarcelos for his feedback in [issue #23](https://github.com/tyabonil/request-promise/issues/23))*
*(Thanks to @hjpbarcelos for his feedback in [issue #23](https://github.com/request/request-promise/issues/23))*

@@ -443,0 +447,0 @@ ## MIT Licensed

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc