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 b9cd97c commit e6f494c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
16 changes: 10 additions & 6 deletions lib/handler/decorator-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ module.exports = class DecoratorHandler {

// New API

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

if (this.#handler.onConnect) {
Expand Down Expand Up @@ -61,15 +61,19 @@ module.exports = class DecoratorHandler {
}

onResponseData (data) {
let ret

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

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

return true
return ret ?? true
}

onResponseEnd (trailers) {
Expand Down Expand Up @@ -102,7 +106,7 @@ module.exports = class DecoratorHandler {

onConnect (...args) {
if (this.#handler.onRequestStart) {
this.#handler.onRequestStart(null, args[0])
this.#handler.onRequestStart(args[0])
}

if (this.#handler.onConnect) {
Expand Down
2 changes: 1 addition & 1 deletion types/dispatcher.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ declare namespace Dispatcher {
}
export type StreamFactory<TOpaque = null> = (data: StreamFactoryData<TOpaque>) => Writable
export interface DispatchHandlers {
onRequestStart?(reserved: null, abort: (err?: Error) => void): void;
onRequestStart?(abort: (err?: Error) => void): void;
onResponseStart?(resume: () => void): boolean;
onResponseHeaders?(headers: Record<string, string>, statusCode: number): boolean;
onResponseData?(chunk: Buffer): boolean;
Expand Down

0 comments on commit e6f494c

Please sign in to comment.