From d8fb3167d2d7f6a05ec3cfac1877e65e484678ad Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Sun, 22 Sep 2024 12:41:43 +0200 Subject: [PATCH] fixup --- lib/handler/decorator-handler.js | 54 +++++++++++--------------------- 1 file changed, 18 insertions(+), 36 deletions(-) diff --git a/lib/handler/decorator-handler.js b/lib/handler/decorator-handler.js index 1d1798c35e3..d5d02c325e8 100644 --- a/lib/handler/decorator-handler.js +++ b/lib/handler/decorator-handler.js @@ -93,31 +93,19 @@ module.exports = class DecoratorHandler { // Old API onRequestSent (...args) { - if (this.#handler.onRequestSent) { - this.#handler.onRequestSent(...args) - } + return this.#handler.onRequestSent?.(...args) } onConnect (...args) { - if (this.#handler.onRequestStart) { - this.#handler.onRequestStart(args[0]) - } - - if (this.#handler.onConnect) { - return this.#handler.onConnect(...args) - } + this.#handler.onRequestStart?.(args[0]) + return this.#handler.onConnect?.(...args) } onError (...args) { this.#onErrorCalled = true - if (this.#handler.onResponseError) { - this.#handler.onResponseError(args[0]) - } - - if (this.#handler.onError) { - return this.#handler.onError(...args) - } + this.#handler.onResponseError?.(args[0]) + return this.#handler.onError?.(...args) } onUpgrade (...args) { @@ -140,22 +128,22 @@ module.exports = class DecoratorHandler { let ret - if (this.#handler.onResponseStart) { - if (this.#handler.onResponseStart(args[2]) === false) { - // TODO (fix): Strictly speaking we should not call onRepsonseHeaders - // after this... - ret = false - } + if (this.#handler.onResponseStart?.(args[2]) === false) { + // TODO (fix): Strictly speaking we should not call onRepsonseHeaders + // after this... + ret = false } if (this.#handler.onResponseHeaders) { - if (this.#handler.onResponseHeaders(util.parseHeaders(args[1]), args[0]) === false) { + const headers = util.parseHeaders(args[1]) + if (this.#handler.onResponseHeaders(headers, args[0]) === false) { ret = false } } if (this.#handler.onHeaders) { - ret ??= this.#handler.onHeaders(...args) + const ret2 = this.#handler.onHeaders?.(...args) + ret ??= ret2 } return ret @@ -165,13 +153,8 @@ module.exports = class DecoratorHandler { assert(!this.#onCompleteCalled) assert(!this.#onErrorCalled) - if (this.#handler.onResponseData) { - this.#handler.onResponseData(args[0]) - } - - if (this.#handler.onData) { - return this.#handler.onData(...args) - } + this.#handler.onResponseData?.(args[0]) + return this.#handler.onData?.(...args) } onComplete (...args) { @@ -181,12 +164,11 @@ module.exports = class DecoratorHandler { this.#onCompleteCalled = true if (this.#handler.onResponseEnd) { - this.#handler.onResponseEnd(util.parseHeaders(args[0])) + const headers = util.parseHeaders(args[0]) + this.#handler.onResponseEnd(headers) } - if (this.#handler.onComplete) { - return this.#handler.onComplete(...args) - } + return this.#handler.onComplete?.(...args) } onBodySent (...args) {