Skip to content

Commit

Permalink
Set default user-agent. Fixes #156
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyruppel committed Mar 22, 2023
1 parent 96ff402 commit dc79a7a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

var request = require('superagent');
var parse = require('querystring').parse;
var version = require('../package.json').version;

/**
* Subclass superagent's Request class so that we can add
Expand All @@ -19,6 +20,9 @@ function Request(method, url) {

// keep track of all request params for oauth signing
this.params = {};

// superagent no longer sets a default user agent header
this.set('user-agent', 'flickr-sdk/' + version);
}

Request.prototype = Object.create(request.Request.prototype);
Expand Down
8 changes: 8 additions & 0 deletions test/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ describe('lib/request', function () {
assert(subject('GET', 'http://www.example.com') instanceof Request);
});

it('has a default user agent', function () {
const req = subject('GET', 'http://www.example.com');

assert.strictEqual(req.get('user-agent'),
'flickr-sdk/' + process.env.npm_package_version
);
});

it('supports request(url, callback)', function () {
var end = sinon.stub(subject.Request.prototype, 'end').returnsThis();
var spy = sinon.spy();
Expand Down

0 comments on commit dc79a7a

Please sign in to comment.