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 e6f494c commit e21ddc6
Showing 1 changed file with 27 additions and 33 deletions.
60 changes: 27 additions & 33 deletions lib/handler/decorator-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,71 +29,65 @@ module.exports = class DecoratorHandler {
// New API

onRequestStart (abort) {
if (this.#handler.onRequestStart) {
this.#handler.onRequestStart(abort)
}

if (this.#handler.onConnect) {
this.#handler.onConnect(abort)
}
this.#handler.onRequestStart?.(abort)
this.#handler.onConnect?.(abort)
}

onResponseStart (resume) {
if (this.#handler.onResponseStart) {
return this.#handler.onResponseStart(resume)
let ret = true

if (this.#handler.onResponseStart?.(resume) === false) {
ret = false
}

this.#resume = resume

return true
return ret
}

onResponseHeaders (headers, statusCode) {
if (this.#handler.onResponseHeaders) {
this.#handler.onResponseHeaders(headers, statusCode)
let ret = true

if (this.#handler.onResponseHeaders?.(headers, statusCode) === false) {
ret = false
}

if (this.#handler.onHeaders) {
this.#handler.onHeaders(statusCode, toRawHeaders(headers), this.#resume)
const rawHeaders = toRawHeaders(headers)
if (this.#handler.onHeaders(statusCode, rawHeaders, this.#resume) === false) {
ret = false
}
}

return true
return ret
}

onResponseData (data) {
let ret
let ret = true

if (this.#handler.onResponseData) {
if (this.#handler.onResponseData(data) === false) {
ret = false
}
if (this.#handler.onResponseData?.(data) === false) {
ret = false
}

if (this.#handler.onData) {
ret ??= this.#handler.onData(data)
if (this.#handler.onData?.(data) === false) {
ret = false
}

return ret ?? true
return ret
}

onResponseEnd (trailers) {
if (this.#handler.onResponseEnd) {
this.#handler.onResponseEnd(trailers)
}
this.#handler.onResponseEnd?.(trailers)

if (this.#handler.onComplete) {
this.#handler.onComplete(toRawHeaders(trailers))
const rawHeaders = toRawHeaders(trailers)
this.#handler.onComplete(rawHeaders)
}
}

onResponseError (err) {
if (this.#handler.onResponseError) {
this.#handler.onResponseError(err)
}

if (this.#handler.onError) {
this.#handler.onError(err)
}
this.#handler.onResponseError?.(err)
this.#handler.onError?.(err)
}

// Old API
Expand Down

0 comments on commit e21ddc6

Please sign in to comment.