diff --git a/lib/dispatcher/client.js b/lib/dispatcher/client.js index 3939b89b5b4..706c75e3fda 100644 --- a/lib/dispatcher/client.js +++ b/lib/dispatcher/client.js @@ -351,6 +351,16 @@ class Client extends DispatcherBase { this[kResume]() }) } + + request (opts, callback) { + if (!opts?.origin) { + const origin = this[kUrl]?.origin + if (origin) { + opts = { ...opts, origin } + } + } + return super.request(opts, callback) + } } function onError (client, err) { diff --git a/lib/dispatcher/dispatcher.js b/lib/dispatcher/dispatcher.js index 24e80f9f08d..824dfb6d822 100644 --- a/lib/dispatcher/dispatcher.js +++ b/lib/dispatcher/dispatcher.js @@ -1,6 +1,5 @@ 'use strict' const EventEmitter = require('node:events') -const { kUrl } = require('../core/symbols') const WrapHandler = require('../handler/wrap-handler') const wrapInterceptor = (dispatch) => (opts, handler) => dispatch(opts, WrapHandler.wrap(handler)) @@ -32,7 +31,7 @@ class Dispatcher extends EventEmitter { throw new TypeError(`invalid interceptor, expected function received ${typeof interceptor}`) } - dispatch = interceptor(dispatch, { url: this[kUrl] }) + dispatch = interceptor(dispatch) dispatch = wrapInterceptor(dispatch) if (dispatch == null || typeof dispatch !== 'function' || dispatch.length !== 2) { diff --git a/lib/dispatcher/pool.js b/lib/dispatcher/pool.js index 08303150add..8649e830502 100644 --- a/lib/dispatcher/pool.js +++ b/lib/dispatcher/pool.js @@ -85,6 +85,16 @@ class Pool extends PoolBase { return dispatcher } } + + request (opts, callback) { + if (!opts?.origin) { + const origin = this[kUrl]?.origin + if (origin) { + opts = { ...opts, origin } + } + } + return super.request(opts, callback) + } } module.exports = Pool diff --git a/lib/interceptor/dns.js b/lib/interceptor/dns.js index 3223601f8d8..9957d952315 100644 --- a/lib/interceptor/dns.js +++ b/lib/interceptor/dns.js @@ -338,17 +338,14 @@ module.exports = interceptorOpts => { return (dispatch, opts) => { return function dnsInterceptor (origDispatchOpts, handler) { - let origin - if (origDispatchOpts.origin) { - origin = origDispatchOpts.origin.constructor === URL - ? origDispatchOpts.origin - : new URL(origDispatchOpts.origin) - } else if (opts.url) { - origin = opts.url - } else { - return handler.onError(new InvalidArgumentError('Origin missing')) + if (!origDispatchOpts.origin) { + return handler.onResponseError(null, new InvalidArgumentError('Origin Missing')) } + const origin = origDispatchOpts.origin.constructor === URL + ? origDispatchOpts.origin + : new URL(origDispatchOpts.origin) + if (isIP(origin.hostname) !== 0) { return dispatch(origDispatchOpts, handler) }