Comparing version 9.2.1 to 9.2.2
{ | ||
"name": "got", | ||
"version": "9.2.1", | ||
"version": "9.2.2", | ||
"description": "Simplified HTTP requests", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -8,6 +8,4 @@ 'use strict'; | ||
const deepFreeze = require('./deep-freeze'); | ||
const mergeInstances = require('./merge-instances'); | ||
const getPromiseOrStream = options => options.stream ? asStream(options) : asPromise(options); | ||
const mergeOptions = (defaults, options = {}) => merge({}, defaults, options); | ||
@@ -46,7 +44,7 @@ const aliases = [ | ||
got.extend = options => create({ | ||
options: mergeOptions(defaults.options, options), | ||
options: merge.options(defaults.options, options), | ||
handler: defaults.handler | ||
}); | ||
got.mergeInstances = (...args) => create(mergeInstances(args)); | ||
got.mergeInstances = (...args) => create(merge.instances(args)); | ||
@@ -60,3 +58,3 @@ got.stream = (url, options) => got(url, {...options, stream: true}); | ||
Object.assign(got, {...errors, mergeOptions}); | ||
Object.assign(got, {...errors, mergeOptions: merge.options}); | ||
Object.defineProperty(got, 'defaults', { | ||
@@ -63,0 +61,0 @@ value: deepFreeze(defaults), |
'use strict'; | ||
const {URL} = require('url'); | ||
const is = require('@sindresorhus/is'); | ||
const knownHookEvents = require('./known-hook-events'); | ||
@@ -32,2 +33,46 @@ const merge = (target, ...sources) => { | ||
const mergeOptions = (...sources) => { | ||
sources = sources.map(source => source || {}); | ||
const merged = merge({}, ...sources); | ||
const hooks = {}; | ||
for (const hook of knownHookEvents) { | ||
hooks[hook] = []; | ||
} | ||
for (const source of sources) { | ||
if (source.hooks) { | ||
for (const hook of knownHookEvents) { | ||
if (hooks[hook]) { | ||
hooks[hook] = hooks[hook].concat(source.hooks[hook]); | ||
} | ||
} | ||
} | ||
} | ||
if (!is.empty(hooks)) { | ||
merged.hooks = hooks; | ||
} | ||
return merged; | ||
}; | ||
const mergeInstances = (instances, methods) => { | ||
const handlers = instances.map(instance => instance.defaults.handler); | ||
const size = instances.length - 1; | ||
return { | ||
methods, | ||
options: mergeOptions(...instances.map(instance => instance.defaults.options)), | ||
handler: (options, next) => { | ||
let iteration = -1; | ||
const iterate = options => handlers[++iteration](options, iteration === size ? next : iterate); | ||
return iterate(options); | ||
} | ||
}; | ||
}; | ||
module.exports = merge; | ||
module.exports.options = mergeOptions; | ||
module.exports.instances = mergeInstances; |
@@ -58,3 +58,4 @@ 'use strict'; | ||
module.exports = (url, options, defaults) => { | ||
options = merge({}, defaults.options, options ? preNormalize(options) : {}); | ||
options = merge({}, defaults.options, options || {}); | ||
options = preNormalize(options); | ||
@@ -61,0 +62,0 @@ if (Reflect.has(options, 'url') || (is.object(url) && Reflect.has(url, 'url'))) { |
@@ -123,5 +123,6 @@ 'use strict'; | ||
const bufferString = Buffer.from(response.headers.location, 'binary').toString(); | ||
redirectUrl = (new URL(bufferString, urlLib.format(options))).toString(); | ||
try { | ||
// Handles invalid URLs. See https://github.com/sindresorhus/got/issues/604 | ||
redirectUrl = (new URL(bufferString, urlLib.format(options))).toString(); | ||
decodeURI(redirectUrl); | ||
@@ -128,0 +129,0 @@ } catch (error) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
73699
1165
20