diff --git a/lib/util/got/host-rules.js b/lib/util/got/host-rules.js index 7fb990085ca2664f38262220c4cd56ab41669b66..e52382c97d2de632c6498f7f6fc2e8e7f3ee4e89 100644 --- a/lib/util/got/host-rules.js +++ b/lib/util/got/host-rules.js @@ -1,3 +1,4 @@ +/* eslint-disable no-param-reassign */ const got = require('got'); const hostRules = require('../host-rules'); @@ -7,26 +8,29 @@ const hostRules = require('../host-rules'); module.exports = got.create({ options: {}, handler: (options, next) => { - const { hostType, ...opts } = options; if (!options.hostname) { - return next(opts); + return next(options); } - const { username = '', password, token, timeout } = hostRules.find({ - hostType, + const { username, password, token, timeout } = hostRules.find({ + hostType: options.hostType, url: options.href, }); - if (opts.headers.authorization || opts.auth || opts.token) { - logger.debug('Authorization already set for host: ' + opts.hostname); + if (options.headers.authorization || options.auth || options.token) { + logger.trace('Authorization already set for host: ' + options.hostname); } else if (password) { - logger.debug('Applying Basic authentication for host ' + opts.hostname); - opts.auth = `${username}:${password}`; + logger.trace( + 'Applying Basic authentication for host ' + options.hostname + ); + options.auth = `${username || ''}:${password}`; } else if (token) { - logger.debug('Applying Bearer authentication for host ' + opts.hostname); - opts.token = token; + logger.trace( + 'Applying Bearer authentication for host ' + options.hostname + ); + options.token = token; } if (timeout) { - opts.gotTimeout = { request: timeout }; + options.gotTimeout = { request: timeout }; } - return next(opts); + return next(options); }, });