diff --git a/lib/common.js b/lib/common.js index ae4966e51..9c5416cfc 100644 --- a/lib/common.js +++ b/lib/common.js @@ -13,8 +13,8 @@ const timers = require('timers') * @param {Object} options - a parsed options object of the request */ function normalizeRequestOptions(options) { - options.proto = options.proto || 'http' - options.port = options.port || (options.proto === 'http' ? 80 : 443) + options.protocol = options.protocol || 'http:' + options.port = options.port || (options.protocol === 'http:' ? 80 : 443) if (options.host) { debug('options.host:', options.host) if (!options.hostname) { @@ -135,14 +135,14 @@ function restoreOverriddenRequests() { * 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. */ -function normalizeOrigin(proto, host, port) { +function normalizeOrigin(protocol, host, port) { const hostHasPort = host.includes(':') const portIsStandard = - (proto === 'http' && (port === 80 || port === '80')) || - (proto === 'https' && (port === 443 || port === '443')) + (protocol === 'http:' && (port === 80 || port === '80')) || + (protocol === 'https:' && (port === 443 || port === '443')) const portStr = hostHasPort || portIsStandard ? '' : `:${port}` - return `${proto}://${host}${portStr}` + return `${protocol}//${host}${portStr}` } /** @@ -150,7 +150,7 @@ function normalizeOrigin(proto, host, port) { * @param {Object} options * @param {string} options.method * @param {number|string} options.port - * @param {string} options.proto Set internally. always http or https + * @param {string} options.protocol Set internally. always http: or https: * @param {string} options.hostname * @param {string} options.path * @param {Object} options.headers @@ -159,7 +159,7 @@ function normalizeOrigin(proto, host, port) { */ function stringifyRequest(options, body) { const { method = 'GET', path = '', port } = options - const origin = normalizeOrigin(options.proto, options.hostname, port) + const origin = normalizeOrigin(options.protocol, options.hostname, port) const log = { method, @@ -620,11 +620,11 @@ function isPlainObject(value) { if (Object.getPrototypeOf(value) === null) { return true } - let proto = value - while (Object.getPrototypeOf(proto) !== null) { - proto = Object.getPrototypeOf(proto) + let prototype = value + while (Object.getPrototypeOf(prototype) !== null) { + prototype = Object.getPrototypeOf(prototype) } - return Object.getPrototypeOf(value) === proto + return Object.getPrototypeOf(value) === prototype } /** diff --git a/lib/intercept.js b/lib/intercept.js index 7710f13b2..202244311 100644 --- a/lib/intercept.js +++ b/lib/intercept.js @@ -147,7 +147,7 @@ function interceptorsFor(options) { debug('interceptors for %j', options.host) - const basePath = `${options.proto}://${options.host}` + const basePath = `${options.protocol}//${options.host}` debug('filtering interceptors for basepath', basePath) @@ -194,22 +194,22 @@ function interceptorsFor(options) { } } - return undefined + return } function removeInterceptor(options) { // Lazily import to avoid circular imports. const Interceptor = require('./interceptor') - let baseUrl, key, method, proto + let baseUrl, key, method, protocol if (options instanceof Interceptor) { baseUrl = options.basePath key = options._key } else { - proto = options.proto ? options.proto : 'http' + protocol = options.protocol ? options.protocol : 'http:' common.normalizeRequestOptions(options) - baseUrl = `${proto}://${options.host}` + baseUrl = `${protocol}//${options.host}` method = (options.method && options.method.toUpperCase()) || 'GET' key = `${method} ${baseUrl}${options.path || '/'}` } diff --git a/lib/interceptor.js b/lib/interceptor.js index 1b273fd6b..4c5eaa755 100644 --- a/lib/interceptor.js +++ b/lib/interceptor.js @@ -250,7 +250,7 @@ module.exports = class Interceptor { let { path = '/' } = options let matches let matchKey - const { proto } = options + const { protocol } = options if (this.method !== method) { this.scope.logger( @@ -330,13 +330,13 @@ module.exports = class Interceptor { } // If we have a filtered scope then we use it instead reconstructing the - // scope from the request options (proto, host and port) as these two won't + // scope from the request options (protocol, host and port) as these two won't // necessarily match and we have to remove the scope that was matched (vs. // that was defined). if (this.__nock_filteredScope) { matchKey = this.__nock_filteredScope } else { - matchKey = common.normalizeOrigin(proto, options.host, options.port) + matchKey = common.normalizeOrigin(protocol, options.host, options.port) } if (typeof this.uri === 'function') { @@ -359,6 +359,7 @@ module.exports = class Interceptor { } matches = matchBody(options, this._requestBody, body) + if (!matches) { this.scope.logger( "bodies don't match: \n", @@ -383,7 +384,7 @@ module.exports = class Interceptor { const method = (options.method || 'GET').toUpperCase() let { path } = options - const { proto } = options + const { protocol } = options // NOTE: Do not split off the query params as the regex could use them if (!isRegex) { @@ -394,7 +395,7 @@ module.exports = class Interceptor { path = this.scope.transformPathFunction(path) } const comparisonKey = isPathFn || isRegex ? this.__nock_scopeKey : this._key - const matchKey = `${method} ${proto}://${options.host}${path}` + const matchKey = `${method} ${protocol}//${options.host}${path}` if (isPathFn) { return !!(matchKey.match(comparisonKey) && this.path(path)) diff --git a/modules/intercept-node-http/lib/socket.js b/modules/intercept-node-http/lib/socket.js index 5f5fdcb66..7e27d7abc 100644 --- a/modules/intercept-node-http/lib/socket.js +++ b/modules/intercept-node-http/lib/socket.js @@ -7,7 +7,7 @@ class Socket extends EventEmitter { super() // Pretend this is a TLSSocket - if (options.proto === 'https') { + if (options.protocol === 'https:') { // https://github.com/nock/nock/issues/158 this.authorized = true // https://github.com/nock/nock/issues/2147 diff --git a/modules/intercept-node-http/lib/utils.js b/modules/intercept-node-http/lib/utils.js index 252946c19..6b2296593 100644 --- a/modules/intercept-node-http/lib/utils.js +++ b/modules/intercept-node-http/lib/utils.js @@ -88,9 +88,9 @@ function isPlainObject(value) { if (Object.getPrototypeOf(value) === null) { return true } - let proto = value - while (Object.getPrototypeOf(proto) !== null) { - proto = Object.getPrototypeOf(proto) + let prototype = value + while (Object.getPrototypeOf(prototype) !== null) { + prototype = Object.getPrototypeOf(prototype) } - return Object.getPrototypeOf(value) === proto + return Object.getPrototypeOf(value) === prototype }