diff --git a/docs/docs/api/Dispatcher.md b/docs/docs/api/Dispatcher.md index 1c51b4ba309..5e28aaefe09 100644 --- a/docs/docs/api/Dispatcher.md +++ b/docs/docs/api/Dispatcher.md @@ -207,7 +207,7 @@ Returns: `Boolean` - `false` if dispatcher is busy and further dispatch calls wo * **onRequestStart** `(controller: DispatchController, context: object) => void` - Invoked before request is dispatched on socket. May be invoked multiple times when a request is retried when the request at the head of the pipeline fails. * **onRequestUpgrade** `(controller: DispatchController, statusCode: number, headers: Record, socket: Duplex) => void` (optional) - Invoked when request is upgraded. Required if `DispatchOptions.upgrade` is defined or `DispatchOptions.method === 'CONNECT'`. -* **onResponseStart** `(controller: DispatchController, statusCode: number, statusMessage?: string, headers: Record) => void` - Invoked when statusCode and headers have been received. May be invoked multiple times due to 1xx informational headers. Not required for `upgrade` requests. +* **onResponseStart** `(controller: DispatchController, statusCode: number, headers: Record, statusMessage?: string) => void` - Invoked when statusCode and headers have been received. May be invoked multiple times due to 1xx informational headers. Not required for `upgrade` requests. * **onResponseData** `(controller: DispatchController, chunk: Buffer) => void` - Invoked when response payload data is received. Not required for `upgrade` requests. * **onResponseEnd** `(controller: DispatchController, trailers: Record) => void` - Invoked when response payload and trailers have been received and the request has completed. Not required for `upgrade` requests. * **onResponseError** `(error: Error) => void` - Invoked when an error has occurred. May not throw. diff --git a/lib/handler/cache-handler.js b/lib/handler/cache-handler.js index 36dc65c1c68..059be122e52 100644 --- a/lib/handler/cache-handler.js +++ b/lib/handler/cache-handler.js @@ -71,15 +71,15 @@ class CacheHandler { onResponseStart ( controller, statusCode, - statusMessage, - headers + headers, + statusMessage ) { const downstreamOnHeaders = () => this.#handler.onResponseStart?.( controller, statusCode, - statusMessage, - headers + headers, + statusMessage ) if ( diff --git a/lib/handler/cache-revalidation-handler.js b/lib/handler/cache-revalidation-handler.js index 96a70683ea8..9672936d9de 100644 --- a/lib/handler/cache-revalidation-handler.js +++ b/lib/handler/cache-revalidation-handler.js @@ -62,8 +62,8 @@ class CacheRevalidationHandler { onResponseStart ( controller, statusCode, - statusMessage, - headers + headers, + statusMessage ) { assert(this.#callback != null) @@ -82,8 +82,8 @@ class CacheRevalidationHandler { this.#handler.onResponseStart?.( controller, statusCode, - statusMessage, - headers + headers, + statusMessage ) } @@ -92,7 +92,7 @@ class CacheRevalidationHandler { return } - return this.#handler.onResponseData(controller, chunk) + return this.#handler.onResponseData?.(controller, chunk) } onResponseEnd (controller, trailers) { diff --git a/lib/handler/redirect-handler.js b/lib/handler/redirect-handler.js index d6f1995ced1..dd28e1d7426 100644 --- a/lib/handler/redirect-handler.js +++ b/lib/handler/redirect-handler.js @@ -90,7 +90,7 @@ class RedirectHandler { this.handler.onRequestUpgrade?.(controller, statusCode, headers, socket) } - onResponseStart (controller, statusCode, statusMessage, headers) { + onResponseStart (controller, statusCode, headers, statusMessage) { if (this.opts.throwOnMaxRedirect && this.history.length >= this.maxRedirections) { throw new Error('max redirects') } @@ -125,7 +125,7 @@ class RedirectHandler { } if (!this.location) { - this.handler.onResponseStart?.(controller, statusCode, statusMessage, headers) + this.handler.onResponseStart?.(controller, statusCode, headers, statusMessage) return } diff --git a/lib/handler/unwrap-handler.js b/lib/handler/unwrap-handler.js index a6b44d99876..865593a327b 100644 --- a/lib/handler/unwrap-handler.js +++ b/lib/handler/unwrap-handler.js @@ -73,7 +73,7 @@ module.exports = class UnwrapHandler { onHeaders (statusCode, rawHeaders, resume, statusMessage) { this.#controller[kResume] = resume - this.#handler.onResponseStart?.(this.#controller, statusCode, statusMessage, parseHeaders(rawHeaders)) + this.#handler.onResponseStart?.(this.#controller, statusCode, parseHeaders(rawHeaders), statusMessage) return !this.#controller.paused } diff --git a/lib/handler/wrap-handler.js b/lib/handler/wrap-handler.js index 3bf49f1be16..271bfb8a177 100644 --- a/lib/handler/wrap-handler.js +++ b/lib/handler/wrap-handler.js @@ -60,7 +60,7 @@ module.exports = class WrapHandler { this.#handler.onUpgrade?.(statusCode, rawHeaders, socket) } - onResponseStart (controller, statusCode, statusMessage, headers) { + onResponseStart (controller, statusCode, headers, statusMessage) { const rawHeaders = [] for (const [key, val] of Object.entries(headers)) { // TODO (fix): What if val is Array diff --git a/lib/interceptor/cache.js b/lib/interceptor/cache.js index d48ac564b42..703b87782ea 100644 --- a/lib/interceptor/cache.js +++ b/lib/interceptor/cache.js @@ -163,7 +163,7 @@ function sendCachedValue (handler, opts, result, age, context) { // TODO (fix): What if headers.age already exists? const headers = age != null ? { ...result.headers, age: String(age) } : result.headers - handler.onResponseStart?.(controller, result.statusCode, result.statusMessage, headers) + handler.onResponseStart?.(controller, result.statusCode, headers, result.statusMessage) if (opts.method === 'HEAD') { stream.destroy() diff --git a/types/dispatcher.d.ts b/types/dispatcher.d.ts index 3c3a32c47f0..17bb44166fa 100644 --- a/types/dispatcher.d.ts +++ b/types/dispatcher.d.ts @@ -226,7 +226,7 @@ declare namespace Dispatcher { export interface DispatchHandler { onRequestStart?(controller: DispatchController, context: any): void; onRequestUpgrade?(controller: DispatchController, statusCode: number, headers: IncomingHttpHeaders, socket: Duplex): void; - onResponseStart?(controller: DispatchController, statusCode: number, statusMessage: string | null, headers: IncomingHttpHeaders): void; + onResponseStart?(controller: DispatchController, statusCode: number, headers: IncomingHttpHeaders, statusMessage?: string): void; onResponseData?(controller: DispatchController, chunk: Buffer): void; onResponseEnd?(controller: DispatchController, trailers: IncomingHttpHeaders): void; onResponseError?(controller: DispatchController, error: Error): void;