From 9c117a606bd5f7b44cee2ad339ab57f187fb9bf2 Mon Sep 17 00:00:00 2001 From: Apoorv Mishra Date: Thu, 13 Jun 2019 19:04:56 +0530 Subject: [PATCH] fix(#1479): disable setting default user-agent Revert "Disable setting default user-agent" This reverts commit 01841cc6fc2e5884b2259bf369d0ffba8d5618c1. Disable setting default user-agent Remove unused var --- src/node/index.js | 4 ---- test/node/user-agent.js | 27 ++------------------------- 2 files changed, 2 insertions(+), 29 deletions(-) diff --git a/src/node/index.js b/src/node/index.js index 87ca7a84f..172e9966b 100644 --- a/src/node/index.js +++ b/src/node/index.js @@ -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'); @@ -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 }; } diff --git a/test/node/user-agent.js b/test/node/user-agent.js index 1254419a4..8f835d88a 100644 --- a/test/node/user-agent.js +++ b/test/node/user-agent.js @@ -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); - })); });