Skip to content

New Hooks API #3874

@ronag

Description

@ronag

I am doing another iteration on this. The primary goal is to support pre-parsed headers in handlers. However, just doing that seems a bit wasteful and I'm hoping to take the interface one step forward:

I am thinking of something the following lines:

interface Controller {
  pause () : void;
  resume () : void;
  abort(err: Error) : void;
  get aborted () : boolean;
  get reason() : Error;
}

type Headers = Record<string, string | string[]>;
type Trailers = Record<string, string | string[]>;

interface Handler {
  onRequestStart(controller: Controller): void;
  // onRequestHeaders(controller: Controller, headers: Headers): Headers;
  // onRequestData(controller: Controller: chunk: Buffer): Buffer;
  // onRequestTrailers(controller: Controller: chunk, trailers: Trailers): Trailers;
  // onRequestEnd(controller: Controller): void;
  // onRequestError(controller: Controller, error: Error): void;
  onResponseStart(controller: Controller, statusCode: number, statusMessage?: string) : void;
  onResponseHeaders(controller: Controller, headers: Headers): void;
  onResponseData(controller: Controller, chunk: Buffer): void;
  onResponseTrailers(controller: Controller, trailers: Trailers): void;
  onResponseEnd(controller: Controller): void;
  onResponseError(controller: Controller, err: Error): void;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions