aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/node/interop/interop_client.js4
-rw-r--r--src/node/src/client.js31
-rw-r--r--src/node/test/surface_test.js20
3 files changed, 38 insertions, 17 deletions
diff --git a/src/node/interop/interop_client.js b/src/node/interop/interop_client.js
index 6d6f9a349e..8ff9b3cff7 100644
--- a/src/node/interop/interop_client.js
+++ b/src/node/interop/interop_client.js
@@ -283,7 +283,7 @@ function authTest(expected_user, scope, client, done) {
if (credential.createScopedRequired() && scope) {
credential = credential.createScoped(scope);
}
- client.updateMetadata = grpc.getGoogleAuthDelegate(credential);
+ client.$updateMetadata = grpc.getGoogleAuthDelegate(credential);
var arg = {
response_type: 'COMPRESSABLE',
response_size: 314159,
@@ -342,7 +342,7 @@ function oauth2Test(expected_user, scope, per_rpc, client, done) {
if (per_rpc) {
updateMetadata('', {}, makeTestCall);
} else {
- client.updateMetadata = updateMetadata;
+ client.$updateMetadata = updateMetadata;
makeTestCall(null, {});
}
});
diff --git a/src/node/src/client.js b/src/node/src/client.js
index d14713f393..90791b4e4c 100644
--- a/src/node/src/client.js
+++ b/src/node/src/client.js
@@ -251,7 +251,7 @@ function makeUnaryRequestFunction(method, serialize, deserialize) {
function makeUnaryRequest(argument, callback, metadata, options) {
/* jshint validthis: true */
var emitter = new EventEmitter();
- var call = getCall(this.channel, method, options);
+ var call = getCall(this.$channel, method, options);
if (metadata === null || metadata === undefined) {
metadata = {};
}
@@ -261,7 +261,7 @@ function makeUnaryRequestFunction(method, serialize, deserialize) {
emitter.getPeer = function getPeer() {
return call.getPeer();
};
- this.updateMetadata(this.auth_uri, metadata, function(error, metadata) {
+ this.$updateMetadata(this.$auth_uri, metadata, function(error, metadata) {
if (error) {
call.cancel();
callback(error);
@@ -320,12 +320,12 @@ function makeClientStreamRequestFunction(method, serialize, deserialize) {
*/
function makeClientStreamRequest(callback, metadata, options) {
/* jshint validthis: true */
- var call = getCall(this.channel, method, options);
+ var call = getCall(this.$channel, method, options);
if (metadata === null || metadata === undefined) {
metadata = {};
}
var stream = new ClientWritableStream(call, serialize);
- this.updateMetadata(this.auth_uri, metadata, function(error, metadata) {
+ this.$updateMetadata(this.$auth_uri, metadata, function(error, metadata) {
if (error) {
call.cancel();
callback(error);
@@ -390,12 +390,12 @@ function makeServerStreamRequestFunction(method, serialize, deserialize) {
*/
function makeServerStreamRequest(argument, metadata, options) {
/* jshint validthis: true */
- var call = getCall(this.channel, method, options);
+ var call = getCall(this.$channel, method, options);
if (metadata === null || metadata === undefined) {
metadata = {};
}
var stream = new ClientReadableStream(call, deserialize);
- this.updateMetadata(this.auth_uri, metadata, function(error, metadata) {
+ this.$updateMetadata(this.$auth_uri, metadata, function(error, metadata) {
if (error) {
call.cancel();
stream.emit('error', error);
@@ -458,12 +458,12 @@ function makeBidiStreamRequestFunction(method, serialize, deserialize) {
*/
function makeBidiStreamRequest(metadata, options) {
/* jshint validthis: true */
- var call = getCall(this.channel, method, options);
+ var call = getCall(this.$channel, method, options);
if (metadata === null || metadata === undefined) {
metadata = {};
}
var stream = new ClientDuplexStream(call, serialize, deserialize);
- this.updateMetadata(this.auth_uri, metadata, function(error, metadata) {
+ this.$updateMetadata(this.$auth_uri, metadata, function(error, metadata) {
if (error) {
call.cancel();
stream.emit('error', error);
@@ -550,12 +550,12 @@ exports.makeClientConstructor = function(methods, serviceName) {
options = {};
}
options['grpc.primary_user_agent'] = 'grpc-node/' + version;
- this.channel = new grpc.Channel(address, credentials, options);
+ this.$channel = new grpc.Channel(address, credentials, options);
// Remove the optional DNS scheme, trailing port, and trailing backslash
address = address.replace(/^(dns:\/{3})?([^:\/]+)(:\d+)?\/?$/, '$2');
- this.server_address = address;
- this.auth_uri = 'https://' + this.server_address + '/' + serviceName;
- this.updateMetadata = updateMetadata;
+ this.$server_address = address;
+ this.$auth_uri = 'https://' + this.server_address + '/' + serviceName;
+ this.$updateMetadata = updateMetadata;
}
/**
@@ -575,13 +575,13 @@ exports.makeClientConstructor = function(methods, serviceName) {
if (err) {
callback(new Error('Failed to connect before the deadline'));
}
- var new_state = self.channel.getConnectivityState(true);
+ var new_state = self.$channel.getConnectivityState(true);
if (new_state === grpc.connectivityState.READY) {
callback();
} else if (new_state === grpc.connectivityState.FATAL_FAILURE) {
callback(new Error('Failed to connect to server'));
} else {
- self.channel.watchConnectivityState(new_state, deadline, checkState);
+ self.$channel.watchConnectivityState(new_state, deadline, checkState);
}
};
checkState();
@@ -589,6 +589,9 @@ exports.makeClientConstructor = function(methods, serviceName) {
_.each(methods, function(attrs, name) {
var method_type;
+ if (_.startsWith(name, '$')) {
+ throw new Error('Method names cannot start with $');
+ }
if (attrs.requestStream) {
if (attrs.responseStream) {
method_type = 'bidi';
diff --git a/src/node/test/surface_test.js b/src/node/test/surface_test.js
index 098905e74b..34c64141f3 100644
--- a/src/node/test/surface_test.js
+++ b/src/node/test/surface_test.js
@@ -132,6 +132,24 @@ describe('Server.prototype.addProtoService', function() {
});
});
});
+describe('Client constructor building', function() {
+ var illegal_service_attrs = {
+ $method : {
+ path: '/illegal/$method',
+ requestStream: false,
+ responseStream: false,
+ requestSerialize: _.identity,
+ requestDeserialize: _.identity,
+ responseSerialize: _.identity,
+ responseDeserialize: _.identity
+ }
+ };
+ it('Should reject method names starting with $', function() {
+ assert.throws(function() {
+ grpc.makeGenericClientConstructor(illegal_service_attrs);
+ }, /\$/);
+ });
+});
describe('Client#$waitForReady', function() {
var server;
var port;
@@ -419,7 +437,7 @@ describe('Other conditions', function() {
server.shutdown();
});
it('channel.getTarget should be available', function() {
- assert.strictEqual(typeof client.channel.getTarget(), 'string');
+ assert.strictEqual(typeof client.$channel.getTarget(), 'string');
});
describe('Server recieving bad input', function() {
var misbehavingClient;