Skip to content

Commit

Permalink
common: add x-goog-api-client to all API requests (#2223)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus authored Apr 14, 2017
1 parent 326ad28 commit fa3e960
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/common/src/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,10 @@ Service.prototype.request_ = function(reqOpts, callback) {

delete reqOpts.interceptors_;

var pkg = this.packageJson;
reqOpts.headers = extend({}, reqOpts.headers, {
'User-Agent': util.getUserAgentFromPackageJson(this.packageJson)
'User-Agent': util.getUserAgentFromPackageJson(pkg),
'x-goog-api-client': `gl-node/${process.versions.node} gccl/${pkg.version}`
});

return this.makeAuthenticatedRequest(reqOpts, callback);
Expand Down
13 changes: 13 additions & 0 deletions packages/common/test/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,19 @@ describe('Service', function() {
service.request_(reqOpts, assert.ifError);
});

it('should add the api-client header', function(done) {
service.makeAuthenticatedRequest = function(reqOpts) {
var pkg = service.packageJson;
assert.strictEqual(
reqOpts.headers['x-goog-api-client'],
`gl-node/${process.versions.node} gccl/${pkg.version}`
);
done();
};

service.request_(reqOpts, assert.ifError);
});

describe('projectIdRequired', function() {
describe('false', function() {
it('should include the projectId', function(done) {
Expand Down

0 comments on commit fa3e960

Please sign in to comment.