diff --git a/lib/interceptor/dns.js b/lib/interceptor/dns.js index 917732646e6..0cacf6cc959 100644 --- a/lib/interceptor/dns.js +++ b/lib/interceptor/dns.js @@ -2,6 +2,7 @@ const { isIP } = require('node:net') const { lookup } = require('node:dns') const DecoratorHandler = require('../handler/decorator-handler') +const WrapHandler = require('../handler/wrap-handler') const { InvalidArgumentError, InformationalError } = require('../core/errors') const maxInt = Math.pow(2, 31) - 1 @@ -224,17 +225,38 @@ class DNSDispatchHandler extends DecoratorHandler { #dispatch = null #handler = null #origin = null + #controller = null constructor (state, { origin, handler, dispatch }, opts) { super(handler) this.#origin = origin - this.#handler = handler + this.#handler = WrapHandler.wrap(handler) this.#opts = { ...opts } this.#state = state this.#dispatch = dispatch } - onError (err) { + onRequestStart (controller, context) { + this.#handler.onRequestStart?.(controller, context) + } + + onRequestUpgrade (controller, statusCode, headers, socket) { + this.handler.onRequestUpgrade?.(controller, statusCode, headers, socket) + } + + onResponseStart (controller, statusCode, headers, statusMessage) { + this.#handler.onResponseStart?.(controller, statusCode, headers, statusMessage) + } + + onResponseData (controller, data) { + this.#handler.onResponseData?.(controller, data) + } + + onResponseEnd (controller, trailers) { + this.#handler.onResponseEnd?.(controller, trailers) + } + + onResponseError (controller, err) { switch (err.code) { case 'ETIMEDOUT': case 'ECONNREFUSED': { @@ -242,7 +264,8 @@ class DNSDispatchHandler extends DecoratorHandler { // We delete the record and retry this.#state.runLookup(this.#origin, this.#opts, (err, newOrigin) => { if (err) { - return this.#handler.onError(err) + this.#handler.onResponseError(controller, err) + return } const dispatchOpts = { @@ -253,18 +276,18 @@ class DNSDispatchHandler extends DecoratorHandler { this.#dispatch(dispatchOpts, this) }) - // if dual-stack disabled, we error out return } - this.#handler.onError(err) - return + // if dual-stack disabled, we error out + this.#handler.onResponseError(controller, err) + break } case 'ENOTFOUND': this.#state.deleteRecord(this.#origin) // eslint-disable-next-line no-fallthrough default: - this.#handler.onError(err) + this.#handler.onResponseError(controller, err) break } }