Comparing version 0.4.9 to 0.4.10
@@ -64,2 +64,3 @@ const HttpProxy = require('http-proxy') | ||
var closed = false | ||
var resolver = helpers.once(resolve) | ||
@@ -73,3 +74,3 @@ forwardReq.once('close', onClose) | ||
function onRetry (err) { | ||
function onRetry (err, res) { | ||
route.emit('proxy:retry', err, forwardReq, res) | ||
@@ -83,9 +84,9 @@ } | ||
} | ||
if (res.headersSent) { | ||
return next() | ||
} | ||
forwardRequest(route, opts, forwardReq, res, next) | ||
} | ||
var called = false | ||
function resolver (err) { | ||
if (called) return | ||
called = true | ||
function resolve (err) { | ||
forwardReq.removeListener('close', onClose) | ||
@@ -92,0 +93,0 @@ done(err) |
@@ -124,6 +124,7 @@ const http = require('http') | ||
function task (cb) { | ||
if (res.headersSent) return cb() | ||
request(params, opts, req, cb) | ||
} | ||
function onRetry (err) { | ||
function onRetry (err, res) { | ||
route.emit('replay:retry', err, req, res) | ||
@@ -130,0 +131,0 @@ } |
const retry = require('retry') | ||
const isFail = require('is-fail') | ||
const once = require('../../helpers').once | ||
@@ -8,8 +9,8 @@ module.exports = function (opts, res, task, done, onRetry) { | ||
// Overwrite response methods | ||
const _writeHead = res.writeHead | ||
const _end = res.end | ||
const proto = Object.getPrototypeOf(res) | ||
// Set methods to noop | ||
res.writeHead = function () {} | ||
res.end = function () {} | ||
res.writeHead = noop | ||
res.write = noop | ||
res.end = noop | ||
@@ -23,13 +24,18 @@ // Create the retrier | ||
function runTask () { | ||
task(handler) | ||
task(once(handler)) | ||
} | ||
function isFailed (err, res) { | ||
return failed(err, res) || err != null | ||
} | ||
function handler (err, proxyRes) { | ||
if (op.retry(failed(err, proxyRes))) { | ||
return onRetry(err) | ||
if (op.retry(isFailed(err, proxyRes))) { | ||
return onRetry(err, proxyRes) | ||
} | ||
// Restore native methods | ||
res.end = _end | ||
res.writeHead = _writeHead | ||
res.end = proto.end | ||
res.write = proto.write | ||
res.writeHead = proto.writeHead | ||
res = null | ||
@@ -40,1 +46,11 @@ | ||
} | ||
function noop () { | ||
// Fake callback resolution | ||
var fn = [].slice.call(arguments).reduce(function (fn, arg) { | ||
if (typeof arg === 'function') fn = arg | ||
return fn | ||
}, null) | ||
if (fn) fn() | ||
return this | ||
} |
{ | ||
"name": "rocky", | ||
"version": "0.4.9", | ||
"version": "0.4.10", | ||
"description": "Full-featured, middleware-oriented, hackable HTTP and WebSocket proxy", | ||
@@ -47,3 +47,3 @@ "repository": "h2non/rocky", | ||
"raw-body": "^2.1.2", | ||
"retry": "^0.6.1", | ||
"retry": "^0.8.0", | ||
"router": "^1.1.1" | ||
@@ -50,0 +50,0 @@ }, |
@@ -28,8 +28,18 @@ const sinon = require('sinon') | ||
test('once', function () { | ||
const spy = sinon.spy() | ||
const fn = helpers.once(spy) | ||
fn('foo') | ||
fn('bar') | ||
expect(spy.calledOnce).to.be.true | ||
expect(spy.args[0]).to.have.length(1) | ||
expect(spy.args[0][0]).to.be.equal('foo') | ||
}) | ||
test('cloneRequest', function () { | ||
var req = new http.IncomingMessage() | ||
const req = new http.IncomingMessage() | ||
req.headers = { foo: 'bar' } | ||
req.rocky = { options: { foo: { bar: true } } } | ||
var newReq = helpers.cloneRequest(req) | ||
const newReq = helpers.cloneRequest(req) | ||
expect(newReq).to.not.be.equal(req) | ||
@@ -44,3 +54,3 @@ expect(newReq.rocky).to.not.be.equal(req.rocky) | ||
test('permute', function () { | ||
var arr = [ 1, 2, 3 ] | ||
const arr = [ 1, 2, 3 ] | ||
expect(arr).to.be.deep.equal([1, 2, 3]) | ||
@@ -56,4 +66,4 @@ helpers.permute(arr) | ||
test('eachSeries', function (done) { | ||
var spy = sinon.spy() | ||
var arr = [ 1, 2, 3 ] | ||
const spy = sinon.spy() | ||
const arr = [ 1, 2, 3 ] | ||
@@ -76,4 +86,4 @@ function iterator (value, next) { | ||
test('eachConcurrently', function (done) { | ||
var spy = sinon.spy() | ||
var arr = [ 1, 2, 3 ] | ||
const spy = sinon.spy() | ||
const arr = [ 1, 2, 3 ] | ||
@@ -80,0 +90,0 @@ function iterator (value, next) { |
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
185658
104
4788
+ Addedretry@0.8.0(transitive)
- Removedretry@0.6.1(transitive)
Updatedretry@^0.8.0