Update checked-in dependencies
This commit is contained in:
parent
7fdbca3ba3
commit
357e0ceaa9
360 changed files with 25673 additions and 917 deletions
108
node_modules/nock/lib/common.js
generated
vendored
108
node_modules/nock/lib/common.js
generated
vendored
|
|
@ -1,9 +1,10 @@
|
|||
'use strict'
|
||||
|
||||
const debug = require('debug')('nock.common')
|
||||
const { common: debug } = require('./debug')
|
||||
const timers = require('timers')
|
||||
const url = require('url')
|
||||
const util = require('util')
|
||||
const http = require('http')
|
||||
|
||||
/**
|
||||
* Normalizes the request options so that it always has `host` property.
|
||||
|
|
@ -50,82 +51,6 @@ function isUtf8Representable(buffer) {
|
|||
return reconstructedBuffer.equals(buffer)
|
||||
}
|
||||
|
||||
// Array where all information about all the overridden requests are held.
|
||||
let requestOverrides = {}
|
||||
|
||||
/**
|
||||
* Overrides the current `request` function of `http` and `https` modules with
|
||||
* our own version which intercepts issues HTTP/HTTPS requests and forwards them
|
||||
* to the given `newRequest` function.
|
||||
*
|
||||
* @param {Function} newRequest - a function handling requests; it accepts four arguments:
|
||||
* - proto - a string with the overridden module's protocol name (either `http` or `https`)
|
||||
* - overriddenRequest - the overridden module's request function already bound to module's object
|
||||
* - options - the options of the issued request
|
||||
* - callback - the callback of the issued request
|
||||
*/
|
||||
function overrideRequests(newRequest) {
|
||||
debug('overriding requests')
|
||||
;['http', 'https'].forEach(function (proto) {
|
||||
debug('- overriding request for', proto)
|
||||
|
||||
const moduleName = proto // 1 to 1 match of protocol and module is fortunate :)
|
||||
const module = require(proto)
|
||||
const overriddenRequest = module.request
|
||||
const overriddenGet = module.get
|
||||
|
||||
if (requestOverrides[moduleName]) {
|
||||
throw new Error(
|
||||
`Module's request already overridden for ${moduleName} protocol.`,
|
||||
)
|
||||
}
|
||||
|
||||
// Store the properties of the overridden request so that it can be restored later on.
|
||||
requestOverrides[moduleName] = {
|
||||
module,
|
||||
request: overriddenRequest,
|
||||
get: overriddenGet,
|
||||
}
|
||||
// https://nodejs.org/api/http.html#http_http_request_url_options_callback
|
||||
module.request = function (input, options, callback) {
|
||||
return newRequest(proto, overriddenRequest.bind(module), [
|
||||
input,
|
||||
options,
|
||||
callback,
|
||||
])
|
||||
}
|
||||
// https://nodejs.org/api/http.html#http_http_get_options_callback
|
||||
module.get = function (input, options, callback) {
|
||||
const req = newRequest(proto, overriddenGet.bind(module), [
|
||||
input,
|
||||
options,
|
||||
callback,
|
||||
])
|
||||
req.end()
|
||||
return req
|
||||
}
|
||||
|
||||
debug('- overridden request for', proto)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Restores `request` function of `http` and `https` modules to values they
|
||||
* held before they were overridden by us.
|
||||
*/
|
||||
function restoreOverriddenRequests() {
|
||||
debug('restoring requests')
|
||||
Object.entries(requestOverrides).forEach(
|
||||
([proto, { module, request, get }]) => {
|
||||
debug('- restoring request for', proto)
|
||||
module.request = request
|
||||
module.get = get
|
||||
debug('- restored request for', proto)
|
||||
},
|
||||
)
|
||||
requestOverrides = {}
|
||||
}
|
||||
|
||||
/**
|
||||
* In WHATWG URL vernacular, this returns the origin portion of a URL.
|
||||
* However, the port is not included if it's standard and not already present on the host.
|
||||
|
|
@ -621,6 +546,7 @@ function clearTimer(clear, ids) {
|
|||
}
|
||||
|
||||
function removeAllTimers() {
|
||||
debug('remove all timers')
|
||||
clearTimer(clearTimeout, timeouts)
|
||||
clearTimer(clearImmediate, immediates)
|
||||
}
|
||||
|
|
@ -653,6 +579,31 @@ function isRequestDestroyed(req) {
|
|||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Request} request
|
||||
*/
|
||||
function convertFetchRequestToClientRequest(request) {
|
||||
const url = new URL(request.url)
|
||||
const options = {
|
||||
...urlToOptions(url),
|
||||
method: request.method,
|
||||
host: url.hostname,
|
||||
port: url.port || (url.protocol === 'https:' ? 443 : 80),
|
||||
path: url.pathname + url.search,
|
||||
proto: url.protocol.slice(0, -1),
|
||||
headers: Object.fromEntries(request.headers.entries()),
|
||||
}
|
||||
|
||||
// By default, Node adds a host header, but for maximum backward compatibility, we are now removing it.
|
||||
// However, we need to consider leaving the header and fixing the tests.
|
||||
if (options.headers.host === options.host) {
|
||||
const { host, ...restHeaders } = options.headers
|
||||
options.headers = restHeaders
|
||||
}
|
||||
|
||||
return new http.ClientRequest(options)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given value is a plain object and not an Array.
|
||||
* @param {*} value
|
||||
|
|
@ -760,12 +711,11 @@ module.exports = {
|
|||
normalizeClientRequestArgs,
|
||||
normalizeOrigin,
|
||||
normalizeRequestOptions,
|
||||
overrideRequests,
|
||||
percentDecode,
|
||||
percentEncode,
|
||||
removeAllTimers,
|
||||
restoreOverriddenRequests,
|
||||
setImmediate,
|
||||
setTimeout,
|
||||
stringifyRequest,
|
||||
convertFetchRequestToClientRequest,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue