aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/node
diff options
context:
space:
mode:
authorGravatar Craig Tiller <craig.tiller@gmail.com>2015-05-08 16:38:32 -0700
committerGravatar Craig Tiller <craig.tiller@gmail.com>2015-05-08 16:38:32 -0700
commit0b488f7649065ad6f00cabbbb617a05dfc7a92e3 (patch)
tree7a9381245a9913b6123910a531a0d1a20a463a14 /src/node
parent2be6095c10353fbcdfbdec50e269775c1a42641d (diff)
parentb8b59b18f2585b602a8c4282ebaf4d5c8bef473a (diff)
Merge github.com:grpc/grpc into churn-churn-churn-the-api-gently-down-the-stream
Conflicts: test/cpp/end2end/async_end2end_test.cc
Diffstat (limited to 'src/node')
-rw-r--r--src/node/index.js7
-rw-r--r--src/node/interop/interop_client.js4
-rw-r--r--src/node/package.json2
-rw-r--r--src/node/src/client.js35
-rw-r--r--src/node/test/math_client_test.js3
-rw-r--r--src/node/test/surface_test.js18
6 files changed, 42 insertions, 27 deletions
diff --git a/src/node/index.js b/src/node/index.js
index 875756328d..c09e416c6e 100644
--- a/src/node/index.js
+++ b/src/node/index.js
@@ -100,22 +100,23 @@ function load(filename, format) {
function getGoogleAuthDelegate(credential) {
/**
* Update a metadata object with authentication information.
+ * @param {string} authURI The uri to authenticate to
* @param {Object} metadata Metadata object
* @param {function(Error, Object)} callback
*/
- return function updateMetadata(metadata, callback) {
+ return function updateMetadata(authURI, metadata, callback) {
metadata = _.clone(metadata);
if (metadata.Authorization) {
metadata.Authorization = _.clone(metadata.Authorization);
} else {
metadata.Authorization = [];
}
- credential.getAccessToken(function(err, token) {
+ credential.getRequestMetadata(authURI, function(err, header) {
if (err) {
callback(err);
return;
}
- metadata.Authorization.push('Bearer ' + token);
+ metadata.Authorization.push(header.Authorization);
callback(null, metadata);
});
};
diff --git a/src/node/interop/interop_client.js b/src/node/interop/interop_client.js
index 3341486b9e..02f341113d 100644
--- a/src/node/interop/interop_client.js
+++ b/src/node/interop/interop_client.js
@@ -260,8 +260,8 @@ function cancelAfterFirstResponse(client, done) {
call.on('data', function(data) {
call.cancel();
});
- call.on('status', function(status) {
- assert.strictEqual(status.code, grpc.status.CANCELLED);
+ call.on('error', function(error) {
+ assert.strictEqual(error.code, grpc.status.CANCELLED);
done();
});
}
diff --git a/src/node/package.json b/src/node/package.json
index 6c0953a83f..0bb3c3d1fd 100644
--- a/src/node/package.json
+++ b/src/node/package.json
@@ -1,6 +1,6 @@
{
"name": "grpc",
- "version": "0.6.2",
+ "version": "0.7.0",
"author": "Google Inc.",
"description": "gRPC Library for Node",
"homepage": "http://www.grpc.io/",
diff --git a/src/node/src/client.js b/src/node/src/client.js
index b2b79e8b70..707a2d99d8 100644
--- a/src/node/src/client.js
+++ b/src/node/src/client.js
@@ -245,6 +245,7 @@ function makeUnaryRequestFunction(method, serialize, deserialize) {
if (response.status.code !== grpc.status.OK) {
var error = new Error(response.status.details);
error.code = response.status.code;
+ error.metadata = response.status.metadata;
callback(error);
return;
}
@@ -316,6 +317,7 @@ function makeClientStreamRequestFunction(method, serialize, deserialize) {
if (response.status.code !== grpc.status.OK) {
var error = new Error(response.status.details);
error.code = response.status.code;
+ error.metadata = response.status.metadata;
callback(error);
return;
}
@@ -382,6 +384,13 @@ function makeServerStreamRequestFunction(method, serialize, deserialize) {
throw err;
}
stream.emit('status', response.status);
+ if (response.status.code !== grpc.status.OK) {
+ var error = new Error(response.status.details);
+ error.code = response.status.code;
+ error.metadata = response.status.metadata;
+ stream.emit('error', error);
+ return;
+ }
});
});
return stream;
@@ -440,6 +449,13 @@ function makeBidiStreamRequestFunction(method, serialize, deserialize) {
throw err;
}
stream.emit('status', response.status);
+ if (response.status.code !== grpc.status.OK) {
+ var error = new Error(response.status.details);
+ error.code = response.status.code;
+ error.metadata = response.status.metadata;
+ stream.emit('error', error);
+ return;
+ }
});
});
return stream;
@@ -469,27 +485,28 @@ var requester_makers = {
* requestSerialize: function to serialize request objects
* responseDeserialize: function to deserialize response objects
* @param {Object} methods An object mapping method names to method attributes
+ * @param {string} serviceName The name of the service
* @return {function(string, Object)} New client constructor
*/
-function makeClientConstructor(methods) {
+function makeClientConstructor(methods, serviceName) {
/**
* Create a client with the given methods
* @constructor
* @param {string} address The address of the server to connect to
* @param {Object} options Options to pass to the underlying channel
- * @param {function(Object, function)=} updateMetadata function to update the
- * metadata for each request
+ * @param {function(string, Object, function)=} updateMetadata function to
+ * update the metadata for each request
*/
function Client(address, options, updateMetadata) {
- if (updateMetadata) {
- this.updateMetadata = updateMetadata;
- } else {
- this.updateMetadata = function(metadata, callback) {
+ if (!updateMetadata) {
+ updateMetadata = function(uri, metadata, callback) {
callback(null, metadata);
};
}
- this.server_address = address;
+ this.server_address = address.replace(/\/$/, '');
this.channel = new grpc.Channel(address, options);
+ this.updateMetadata = _.partial(updateMetadata,
+ this.server_address + '/' + serviceName);
}
_.each(methods, function(attrs, name) {
@@ -525,7 +542,7 @@ function makeClientConstructor(methods) {
* @return {function(string, Object)} New client constructor
*/
function makeProtobufClientConstructor(service) {
- var method_attrs = common.getProtobufServiceAttrs(service);
+ var method_attrs = common.getProtobufServiceAttrs(service, service.name);
var Client = makeClientConstructor(method_attrs);
Client.service = service;
diff --git a/src/node/test/math_client_test.js b/src/node/test/math_client_test.js
index 79df97871b..3461922e66 100644
--- a/src/node/test/math_client_test.js
+++ b/src/node/test/math_client_test.js
@@ -130,8 +130,7 @@ describe('Math client', function() {
});
call.write({dividend: 7, divisor: 0});
call.end();
- call.on('status', function checkStatus(status) {
- assert.notEqual(status.code, grpc.status.OK);
+ call.on('error', function checkStatus(status) {
done();
});
});
diff --git a/src/node/test/surface_test.js b/src/node/test/surface_test.js
index 6f63f1044f..38f9028bff 100644
--- a/src/node/test/surface_test.js
+++ b/src/node/test/surface_test.js
@@ -278,9 +278,8 @@ describe('Trailing metadata', function() {
it('should be present when a server stream call fails', function(done) {
var call = client.serverStream({error: true});
call.on('data', function(){});
- call.on('status', function(status) {
- assert.notStrictEqual(status.code, grpc.status.OK);
- assert.deepEqual(status.metadata.metadata, ['yes']);
+ call.on('error', function(error) {
+ assert.deepEqual(error.metadata.metadata, ['yes']);
done();
});
});
@@ -302,9 +301,8 @@ describe('Trailing metadata', function() {
call.write({error: true});
call.end();
call.on('data', function(){});
- call.on('status', function(status) {
- assert.notStrictEqual(status.code, grpc.status.OK);
- assert.deepEqual(status.metadata.metadata, ['yes']);
+ call.on('error', function(error) {
+ assert.deepEqual(error.metadata.metadata, ['yes']);
done();
});
});
@@ -345,16 +343,16 @@ describe('Cancelling surface client', function() {
});
it('Should correctly cancel a server stream call', function(done) {
var call = client.fib({'limit': 5});
- call.on('status', function(status) {
- assert.strictEqual(status.code, surface_client.status.CANCELLED);
+ call.on('error', function(error) {
+ assert.strictEqual(error.code, surface_client.status.CANCELLED);
done();
});
call.cancel();
});
it('Should correctly cancel a bidi stream call', function(done) {
var call = client.divMany();
- call.on('status', function(status) {
- assert.strictEqual(status.code, surface_client.status.CANCELLED);
+ call.on('error', function(error) {
+ assert.strictEqual(error.code, surface_client.status.CANCELLED);
done();
});
call.cancel();