Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable setting default user-agent #1495

Merged
merged 1 commit into from
Jun 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}));
});