Skip to content

Commit

Permalink
Don't mutate response data
Browse files Browse the repository at this point in the history
  • Loading branch information
markyen committed Feb 12, 2015
1 parent fcd0ff8 commit 7279519
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
16 changes: 8 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -857,8 +857,8 @@ RingPop.prototype.handleOrProxyAll =

dests.forEach(function(dest) {
var res = hammock.Response();
res.on('response', function(err, data) {
onResponse(err, data, dest);
res.on('response', function(err, response) {
onResponse(err, response, dest);
});
if (whoami === dest) {
self.logger.trace('handleOrProxyAll was handled', {
Expand All @@ -882,12 +882,12 @@ RingPop.prototype.handleOrProxyAll =
}
});

function onResponse(err, data, dest) {
if (data) {
data.dest = dest;
data.keys = keysByDest[dest];
}
responses[dest] = data;
function onResponse(err, response, dest) {
responses[dest] = {
res: response,
dest: dest,
keys: keysByDest[dest]
};
if ((--pending === 0 || err) && cb) {
cb(err, responses);
cb = null;
Expand Down
8 changes: 4 additions & 4 deletions test/integration/handle_or_proxy_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ test('handleOrProxyAll() proxies and calls local handler', function t(assert) {
createHandler: createServerHandler
}, function onReady() {
var k = cluster.keys;
var keys = [k.one, k.two, k.two, k.three]
var keys = [k.one, k.two, k.two, k.three];

cluster.requestAll({
keys: keys,
Expand All @@ -81,10 +81,10 @@ test('handleOrProxyAll() proxies and calls local handler', function t(assert) {
assert.equal(hosts.length, 3);
hosts.forEach(function(host) {
var data = responses[host];
assert.equal(data.statusCode, 200);
assert.equal(data.res.statusCode, 200);
tryIt(function parse() {
data.body = JSON.parse(data.body);
assert.equal(data.body.payload.hello, true);
var body = JSON.parse(data.res.body);
assert.equal(body.payload.hello, true);
}, assert.ifError);
});
assert.equal(handlerCallCounts.one, 1);
Expand Down

0 comments on commit 7279519

Please sign in to comment.