Skip to content

Commit

Permalink
Disable setting default user-agent (#1495)
Browse files Browse the repository at this point in the history
Revert "Disable setting default user-agent"

This reverts commit 01841cc6fc2e5884b2259bf369d0ffba8d5618c1.

Disable setting default user-agent

Remove unused var
  • Loading branch information
apoorv-mishra authored and niftylettuce committed Jun 15, 2019
1 parent 483f816 commit e652b8c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 29 deletions.
4 changes: 0 additions & 4 deletions src/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const semver = require('semver');
const safeStringify = require('fast-safe-stringify');

const utils = require('../utils');
const pkg = require('../../package.json');
const RequestBase = require('../request-base');
const { unzip } = require('./unzip');
const Response = require('./response');
Expand Down Expand Up @@ -132,14 +131,11 @@ exports.buffer = {};
* @api private
*/
function _initHeaders(req) {
const ua = `node-superagent/${pkg.version}`;
req._header = {
// coerces header names to lowercase
'user-agent': ua
};
req.header = {
// preserves header name case
'User-Agent': ua
};
}

Expand Down
27 changes: 2 additions & 25 deletions test/node/user-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,9 @@ const setup = require('../support/setup');
const base = setup.uri;

describe('req.get()', () => {
it('should set a default user-agent', () =>
it('should not set a default user-agent', () =>
request.get(`${base}/ua`).then(res => {
assert(res.headers);
assert(res.headers['user-agent']);
assert(
/^node-superagent\/\d+\.\d+\.\d+(?:-[a-z]+\.\d+|$)/.test(
res.headers['user-agent']
)
);
assert(!res.headers['user-agent']);
}));

it('should be able to override user-agent', () =>
request
.get(`${base}/ua`)
.set('User-Agent', 'foo/bar')
.then(res => {
assert(res.headers);
assert.equal(res.headers['user-agent'], 'foo/bar');
}));

it('should be able to wipe user-agent', () =>
request
.get(`${base}/ua`)
.unset('User-Agent')
.then(res => {
assert(res.headers);
assert.equal(res.headers['user-agent'], void 0);
}));
});

0 comments on commit e652b8c

Please sign in to comment.