Skip to content

Commit 3029bd8

Browse files
authored
fix: move statusMessage as optional arg in end (#3886)
1 parent 57866b1 commit 3029bd8

File tree

8 files changed

+16
-16
lines changed

8 files changed

+16
-16
lines changed

docs/docs/api/Dispatcher.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ Returns: `Boolean` - `false` if dispatcher is busy and further dispatch calls wo
207207

208208
* **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.
209209
* **onRequestUpgrade** `(controller: DispatchController, statusCode: number, headers: Record<string, string | string[]>, socket: Duplex) => void` (optional) - Invoked when request is upgraded. Required if `DispatchOptions.upgrade` is defined or `DispatchOptions.method === 'CONNECT'`.
210-
* **onResponseStart** `(controller: DispatchController, statusCode: number, statusMessage?: string, headers: Record<string, string | 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.
210+
* **onResponseStart** `(controller: DispatchController, statusCode: number, headers: Record<string, string | string []>, 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.
211211
* **onResponseData** `(controller: DispatchController, chunk: Buffer) => void` - Invoked when response payload data is received. Not required for `upgrade` requests.
212212
* **onResponseEnd** `(controller: DispatchController, trailers: Record<string, string | string[]>) => void` - Invoked when response payload and trailers have been received and the request has completed. Not required for `upgrade` requests.
213213
* **onResponseError** `(error: Error) => void` - Invoked when an error has occurred. May not throw.

lib/handler/cache-handler.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,15 @@ class CacheHandler {
7171
onResponseStart (
7272
controller,
7373
statusCode,
74-
statusMessage,
75-
headers
74+
headers,
75+
statusMessage
7676
) {
7777
const downstreamOnHeaders = () =>
7878
this.#handler.onResponseStart?.(
7979
controller,
8080
statusCode,
81-
statusMessage,
82-
headers
81+
headers,
82+
statusMessage
8383
)
8484

8585
if (

lib/handler/cache-revalidation-handler.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ class CacheRevalidationHandler {
6262
onResponseStart (
6363
controller,
6464
statusCode,
65-
statusMessage,
66-
headers
65+
headers,
66+
statusMessage
6767
) {
6868
assert(this.#callback != null)
6969

@@ -82,8 +82,8 @@ class CacheRevalidationHandler {
8282
this.#handler.onResponseStart?.(
8383
controller,
8484
statusCode,
85-
statusMessage,
86-
headers
85+
headers,
86+
statusMessage
8787
)
8888
}
8989

@@ -92,7 +92,7 @@ class CacheRevalidationHandler {
9292
return
9393
}
9494

95-
return this.#handler.onResponseData(controller, chunk)
95+
return this.#handler.onResponseData?.(controller, chunk)
9696
}
9797

9898
onResponseEnd (controller, trailers) {

lib/handler/redirect-handler.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class RedirectHandler {
9090
this.handler.onRequestUpgrade?.(controller, statusCode, headers, socket)
9191
}
9292

93-
onResponseStart (controller, statusCode, statusMessage, headers) {
93+
onResponseStart (controller, statusCode, headers, statusMessage) {
9494
if (this.opts.throwOnMaxRedirect && this.history.length >= this.maxRedirections) {
9595
throw new Error('max redirects')
9696
}
@@ -125,7 +125,7 @@ class RedirectHandler {
125125
}
126126

127127
if (!this.location) {
128-
this.handler.onResponseStart?.(controller, statusCode, statusMessage, headers)
128+
this.handler.onResponseStart?.(controller, statusCode, headers, statusMessage)
129129
return
130130
}
131131

lib/handler/unwrap-handler.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ module.exports = class UnwrapHandler {
7373

7474
onHeaders (statusCode, rawHeaders, resume, statusMessage) {
7575
this.#controller[kResume] = resume
76-
this.#handler.onResponseStart?.(this.#controller, statusCode, statusMessage, parseHeaders(rawHeaders))
76+
this.#handler.onResponseStart?.(this.#controller, statusCode, parseHeaders(rawHeaders), statusMessage)
7777
return !this.#controller.paused
7878
}
7979

lib/handler/wrap-handler.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ module.exports = class WrapHandler {
6060
this.#handler.onUpgrade?.(statusCode, rawHeaders, socket)
6161
}
6262

63-
onResponseStart (controller, statusCode, statusMessage, headers) {
63+
onResponseStart (controller, statusCode, headers, statusMessage) {
6464
const rawHeaders = []
6565
for (const [key, val] of Object.entries(headers)) {
6666
// TODO (fix): What if val is Array

lib/interceptor/cache.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ function sendCachedValue (handler, opts, result, age, context) {
163163
// TODO (fix): What if headers.age already exists?
164164
const headers = age != null ? { ...result.headers, age: String(age) } : result.headers
165165

166-
handler.onResponseStart?.(controller, result.statusCode, result.statusMessage, headers)
166+
handler.onResponseStart?.(controller, result.statusCode, headers, result.statusMessage)
167167

168168
if (opts.method === 'HEAD') {
169169
stream.destroy()

types/dispatcher.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ declare namespace Dispatcher {
226226
export interface DispatchHandler {
227227
onRequestStart?(controller: DispatchController, context: any): void;
228228
onRequestUpgrade?(controller: DispatchController, statusCode: number, headers: IncomingHttpHeaders, socket: Duplex): void;
229-
onResponseStart?(controller: DispatchController, statusCode: number, statusMessage: string | null, headers: IncomingHttpHeaders): void;
229+
onResponseStart?(controller: DispatchController, statusCode: number, headers: IncomingHttpHeaders, statusMessage?: string): void;
230230
onResponseData?(controller: DispatchController, chunk: Buffer): void;
231231
onResponseEnd?(controller: DispatchController, trailers: IncomingHttpHeaders): void;
232232
onResponseError?(controller: DispatchController, error: Error): void;

0 commit comments

Comments
 (0)