Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Sep 22, 2024
1 parent e21ddc6 commit d8fb316
Showing 1 changed file with 18 additions and 36 deletions.
54 changes: 18 additions & 36 deletions lib/handler/decorator-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit d8fb316

Please sign in to comment.