Skip to content

Commit

Permalink
feat: append ctx to request (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
gxcsoccer authored Oct 6, 2018
1 parent 513aa96 commit 4341a41
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions lib/client/consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class RpcConsumer extends Base {
requestProps: options.requestProps,
codecType: options.codecType,
timeout: options.responseTimeout || this.options.responseTimeout,
ctx: options.ctx,
});
}

Expand Down
1 change: 1 addition & 0 deletions lib/client/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class RpcRequest {
this.requestProps = data.requestProps || {
service: data.serverSignature,
};
this.ctx = data.ctx;
this.meta = {
id: null,
resultCode: '00',
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@
"await-first": "^1.0.0",
"byte": "^2.0.0",
"cluster-client": "^2.1.1",
"debug": "^4.0.0",
"debug": "^4.0.1",
"easy-table": "^1.1.1",
"graceful": "^1.0.1",
"is-type-of": "^1.2.0",
"is-type-of": "^1.2.1",
"mz-modules": "^2.1.0",
"pump": "^3.0.0",
"sdk-base": "^3.5.0",
"sdk-base": "^3.5.1",
"sofa-bolt-node": "^1.0.2",
"urlencode": "^1.1.0",
"utility": "^1.14.0",
"utility": "^1.15.0",
"zookeeper-cluster-client": "^2.0.1"
},
"devDependencies": {
Expand All @@ -54,8 +54,8 @@
"await-event": "^2.1.0",
"coffee": "^5.1.0",
"contributors": "^0.5.1",
"egg-bin": "^4.8.5",
"eslint": "^5.5.0",
"egg-bin": "^4.9.0",
"eslint": "^5.6.1",
"eslint-config-egg": "^7.1.0",
"mm": "^2.4.1",
"pedding": "^1.1.0"
Expand Down
4 changes: 3 additions & 1 deletion test/client/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ describe('test/client/client.test.js', () => {
name: 'Peter',
group: 'A',
}];
const res = await consumer.invoke('echoObj', args);
const ctx = { foo: 'bar' };
const res = await consumer.invoke('echoObj', args, { ctx });
assert.deepEqual(res, { code: 200, message: 'hello Peter, you are in A' });

assert(req && req.targetAppName === 'pb');
assert(req.ctx === ctx);

await client.close();
});
Expand Down

0 comments on commit 4341a41

Please sign in to comment.