From 198a1ad966cb38ccc1697961914fa5b8b854df2f Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Tue, 21 Jul 2015 14:27:56 -0700 Subject: Added user-agent setting code, and a test for it --- src/node/src/client.js | 6 +++++- src/node/test/surface_test.js | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/node/src/client.js b/src/node/src/client.js index b7bad949d4..06a0f3637f 100644 --- a/src/node/src/client.js +++ b/src/node/src/client.js @@ -47,6 +47,7 @@ var Readable = stream.Readable; var Writable = stream.Writable; var Duplex = stream.Duplex; var util = require('util'); +var version = require('../package.json').version; util.inherits(ClientWritableStream, Writable); @@ -517,7 +518,10 @@ function makeClientConstructor(methods, serviceName) { callback(null, metadata); }; } - + if (!options) { + options = {}; + } + options.GRPC_ARG_PRIMARY_USER_AGENT_STRING = 'grpc-node/' + version; this.server_address = address.replace(/\/$/, ''); this.channel = new grpc.Channel(address, options); this.auth_uri = this.server_address + '/' + serviceName; diff --git a/src/node/test/surface_test.js b/src/node/test/surface_test.js index 18178e49e4..3cb68f8cd8 100644 --- a/src/node/test/surface_test.js +++ b/src/node/test/surface_test.js @@ -258,6 +258,16 @@ describe('Echo metadata', function() { }); call.end(); }); + it('shows the correct user-agent string', function(done) { + var version = require('../package.json').version; + var call = client.unary({}, function(err, data) { + assert.ifError(err); + }, {key: ['value']}); + call.on('metadata', function(metadata) { + assert(_.startsWith(metadata['user-agent'], 'grpc-node/' + version)); + done(); + }); + }); }); describe('Other conditions', function() { var client; -- cgit v1.2.3