diff --git a/lib/helpers/request.js b/lib/helpers/request.js index c4927d203..c686da1dd 100644 --- a/lib/helpers/request.js +++ b/lib/helpers/request.js @@ -1,11 +1,8 @@ -const { Agent: HttpAgent } = require('http'); -const { Agent: HttpsAgent } = require('https'); - const got = require('got'); const CacheableLookup = require('cacheable-lookup'); const QuickLRU = require('quick-lru'); -const omitBy = require('./_/omit_by'); +const pickBy = require('./_/pick_by'); const instance = require('./weak_cache'); const cacheable = new CacheableLookup({ @@ -20,21 +17,18 @@ module.exports = async function request(options) { // eslint-disable-next-line no-param-reassign options.headers['user-agent'] = undefined; const { timeout, agent, lookup } = instance(this).configuration('httpOptions')(new URL(options.url)); - const helperOptions = omitBy({ timeout, agent, lookup }, Boolean); + const helperOptions = pickBy({ timeout, agent, lookup }, Boolean); if (helperOptions.timeout !== undefined && typeof helperOptions.timeout !== 'number') { throw new TypeError('"timeout" http request option must be a number'); } if (helperOptions.agent !== undefined && typeof helperOptions.agent !== 'number') { - if (!(agent instanceof HttpsAgent) && !(agent instanceof HttpAgent)) { - throw new TypeError('"agent" http request option must be an instance of https.Agent or http.Agent depending on the protocol used'); - } - helperOptions.agent = { [options.url.protocol]: helperOptions.agent }; + helperOptions.agent = { [options.url.protocol.slice(0, -1)]: helperOptions.agent }; } if (helperOptions.lookup !== undefined && typeof helperOptions.lookup !== 'function') { - throw new TypeError('"agent" http request option must be a function'); + throw new TypeError('"lookup" http request option must be a function'); } return got({