good-guy-http
Advanced tools
Comparing version 1.8.0 to 1.9.0
@@ -1,2 +0,1 @@ | ||
var Promise = require('bluebird'); | ||
var clone = require('clone'); | ||
@@ -46,2 +45,7 @@ | ||
evict: function(key) { | ||
delete this._entryMap[key]; | ||
return Promise.resolve(); | ||
}, | ||
_markAsRecent: function(key) { | ||
@@ -48,0 +52,0 @@ var index = this._entryOrder.indexOf(key); |
@@ -1,3 +0,1 @@ | ||
var Promise = require('bluebird'); | ||
module.exports = nullCache; | ||
@@ -8,4 +6,5 @@ | ||
store: function(key, object) { return Promise.resolve(); }, | ||
retrieve: function(key) { return Promise.resolve(undefined); } | ||
retrieve: function(key) { return Promise.resolve(undefined); }, | ||
evict: function(key) { return Promise.resolve(); } | ||
}; | ||
} |
@@ -24,3 +24,3 @@ var _ = require('underscore'); | ||
var Promise = circuitBreakerOptions.promise || global.Promise || require('bluebird'); | ||
var Promise = circuitBreakerOptions.promise || global.Promise; | ||
var circuitBreakers = {}; | ||
@@ -27,0 +27,0 @@ |
@@ -44,4 +44,4 @@ var _ = require('underscore'); | ||
// undefined means built-in Promises will be chosen, or bluebird if those aren't available | ||
usePromise: undefined, | ||
// undefined means built-in Promises will be chosen | ||
usePromise: Promise, | ||
@@ -103,3 +103,3 @@ // if needed, you can override the request lib used - just pass it in | ||
if (config.usePromise === undefined) | ||
config.usePromise = global.Promise || require('bluebird'); | ||
config.usePromise = global.Promise; | ||
@@ -106,0 +106,0 @@ var Promise = config.usePromise; |
@@ -24,3 +24,7 @@ var util = require('util'); | ||
function makePromisedRequest(requestOptions) { | ||
return new Promise(function(resolve, reject) { | ||
var externalReject; | ||
var externalHttpReq; | ||
var promise = new Promise(function(resolve, reject) { | ||
externalReject = reject; | ||
var httpReq = request(requestOptions, function(err, response) { | ||
@@ -46,2 +50,3 @@ // hard errors cause a promise rejection | ||
}); | ||
externalHttpReq = httpReq; | ||
@@ -53,2 +58,6 @@ // we want to bail early if a response goes over a chosen size | ||
}); | ||
if (process.env.GG_ABORTABLE_REQUEST) { | ||
makePromisedRequestAbortable(promise, requestOptions, externalHttpReq, externalReject); | ||
} | ||
return promise; | ||
} | ||
@@ -97,2 +106,11 @@ | ||
} | ||
function makePromisedRequestAbortable(promised, requestOptions, request, rejectionCallback) { | ||
promised.abort = function() { | ||
request.abort.call(request); | ||
var err = new AbortedRequestError(); | ||
err = augmentError(err, requestOptions); | ||
rejectionCallback(err); | ||
}; | ||
} | ||
} | ||
@@ -106,1 +124,9 @@ | ||
util.inherits(ResponseSizeExceededError, Error); | ||
var AbortedRequestError = function() { | ||
Error.call(this); | ||
this.message = 'HTTP request aborted'; | ||
this.code = 'EREQUESTABORTED'; | ||
this.unretriable = true; | ||
}; | ||
util.inherits(AbortedRequestError, Error); |
{ | ||
"name": "good-guy-http", | ||
"version": "1.8.0", | ||
"version": "1.9.0", | ||
"description": "The opinionated sane HTTP client with a good guy approach.", | ||
@@ -17,4 +17,6 @@ "main": "lib/index.js", | ||
"license": "MIT", | ||
"engines": { | ||
"node": ">=0.12" | ||
}, | ||
"dependencies": { | ||
"bluebird": "3.3.1", | ||
"circuit-breaker-js": "Schibsted-Tech-Polska/circuit-breaker-js#v0.0.2", | ||
@@ -21,0 +23,0 @@ "clone": "1.0.2", |
@@ -55,4 +55,4 @@ # good-guy-http | ||
usePromise: require('bluebird'), // Promise constructor to use, you may want to replace bluebird with | ||
// different implementation, like q or native Promise | ||
usePromise: Promise, // Promise constructor to use, you may want to replace native Promise with | ||
// different implementation, like q or bluebird | ||
@@ -114,2 +114,3 @@ defaultCaching: { // default caching settings for responses without Cache-Control | ||
* `retrieve(key)` - returning a promise that resolves with the previously stored object, or undefined if no object is found | ||
* `evict(key)` - returning a promise that resolves when the object is evicted from cache | ||
@@ -116,0 +117,0 @@ By default, an in-memory cache limited to the 500 most recently used requests is used, but you can easily override this: |
@@ -1,3 +0,1 @@ | ||
var Promise = require('bluebird'); | ||
/** | ||
@@ -4,0 +2,0 @@ * Inverts a promise: rejections turns into successes (with error as the value), |
@@ -1,2 +0,1 @@ | ||
var Promise = require('bluebird'); | ||
var express = require('express'); | ||
@@ -3,0 +2,0 @@ var http = require('http'); |
var sinon = require('sinon'); | ||
var Promise = global.Promise || require('bluebird'); | ||
var assert = require('assert'); | ||
@@ -4,0 +3,0 @@ var lib = require('../../'); |
var assert = require('assert'); | ||
var _ = require('underscore'); | ||
var Promise = require('bluebird'); | ||
var lib = require('../../'); | ||
@@ -5,0 +4,0 @@ var expectRejection = require('../helpers').expectRejection; |
var _ = require('underscore'); | ||
var assert = require('assert'); | ||
var Promise = require('bluebird'); | ||
@@ -5,0 +4,0 @@ describe("Requests with collapsing", function() { |
var _ = require('underscore'); | ||
var assert = require('assert'); | ||
var Promise = require('bluebird'); | ||
@@ -5,0 +4,0 @@ describe("Convenience methods", function() { |
@@ -14,3 +14,3 @@ var assert = require('assert'); | ||
it("should use built-in Promises, if available", function(done) { | ||
it("should use built-in Promises by default", function(done) { | ||
var gghttp = require('../../')({ | ||
@@ -23,4 +23,3 @@ maxRetries: 0, | ||
var promise = gghttp(app.url("/return-body/hello")).then(function () { | ||
var defaultCtorForThisNodeVersion = global.Promise || require('bluebird'); | ||
assert.ok(promise instanceof defaultCtorForThisNodeVersion); | ||
assert.ok(promise instanceof Promise); | ||
done(); | ||
@@ -27,0 +26,0 @@ }).catch(done); |
var _ = require('underscore'); | ||
var assert = require('assert'); | ||
var Promise = require('bluebird'); | ||
var lib = require('../../'); | ||
@@ -5,0 +4,0 @@ var mockTimer = require('../helpers').mockTimer; |
@@ -1,2 +0,1 @@ | ||
var Promise = require('bluebird'); | ||
var assert = require('assert'); | ||
@@ -3,0 +2,0 @@ var lib = require('../../'); |
var _ = require('underscore'); | ||
var assert = require('assert'); | ||
var Promise = require('bluebird'); | ||
@@ -5,0 +4,0 @@ describe('Reconfiguration', function() { |
var assert = require('assert'); | ||
var _ = require('underscore'); | ||
var Promise = global.Promise || require('bluebird'); | ||
@@ -5,0 +4,0 @@ var circuitBreaking = require('../../lib/circuit-breaking'); |
var assert = require('assert'); | ||
var Promise = require('bluebird'); | ||
var LRUCache = require('../../lib/caching/lru-cache'); | ||
@@ -16,2 +15,13 @@ | ||
it('should be able to evict elements', function(done) { | ||
var lru = new LRUCache(2); | ||
lru.store('hitchhiker', {answer: 42}).then(function() { | ||
return lru.evict('hitchhiker'); | ||
}).then(function() { | ||
return lru.retrieve('hitchhiker'); | ||
}).then(function(object) { | ||
assert.equal(object, undefined); | ||
}).then(done).catch(done); | ||
}); | ||
it('should store values rather than references to elements', function(done) { | ||
@@ -18,0 +28,0 @@ var lru = new LRUCache(2); |
var assert = require('assert'); | ||
var Promise = require('bluebird'); | ||
var waitFor = require('../helpers').waitFor; | ||
@@ -4,0 +3,0 @@ |
var request = require('request'); | ||
var assert = require('assert'); | ||
var Promise = require('bluebird'); | ||
var expectRejection = require('./../helpers').expectRejection; | ||
var waitFor = require('./../helpers').waitFor; | ||
@@ -91,4 +91,15 @@ describe("Promised requests", function() { | ||
}).then(done).catch(done); | ||
}); | ||
}); | ||
if (process.env.GG_ABORTABLE_REQUEST) { | ||
it("should expose method to abort the request", function (done) { | ||
var promised = req(app.url('/delay-for-ms/400')); | ||
expectRejection(promised).then(function (err) { | ||
assert.equal(err.code, 'EREQUESTABORTED'); | ||
}).then(done).catch(done); | ||
waitFor(1).then(function () { | ||
promised.abort(); | ||
}); | ||
}); | ||
} | ||
}); | ||
@@ -95,0 +106,0 @@ |
Sorry, the diff of this file is not supported yet
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
94413
5
2197
181
3
- Removedbluebird@3.3.1
- Removedbluebird@3.3.1(transitive)