Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: move statusMessage as optional arg in end #3886

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/docs/api/Dispatcher.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string | string[]>, 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<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.
* **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.
* **onResponseData** `(controller: DispatchController, chunk: Buffer) => void` - Invoked when response payload data is received. Not required for `upgrade` requests.
* **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.
* **onResponseError** `(error: Error) => void` - Invoked when an error has occurred. May not throw.
Expand Down
8 changes: 4 additions & 4 deletions lib/handler/cache-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ class CacheHandler {
onResponseStart (
controller,
statusCode,
statusMessage,
headers
headers,
statusMessage
) {
const downstreamOnHeaders = () =>
this.#handler.onResponseStart?.(
controller,
statusCode,
statusMessage,
headers
headers,
statusMessage
)

if (
Expand Down
10 changes: 5 additions & 5 deletions lib/handler/cache-revalidation-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ class CacheRevalidationHandler {
onResponseStart (
controller,
statusCode,
statusMessage,
headers
headers,
statusMessage
) {
assert(this.#callback != null)

Expand All @@ -82,8 +82,8 @@ class CacheRevalidationHandler {
this.#handler.onResponseStart?.(
controller,
statusCode,
statusMessage,
headers
headers,
statusMessage
)
}

Expand All @@ -92,7 +92,7 @@ class CacheRevalidationHandler {
return
}

return this.#handler.onResponseData(controller, chunk)
return this.#handler.onResponseData?.(controller, chunk)
}

onResponseEnd (controller, trailers) {
Expand Down
4 changes: 2 additions & 2 deletions lib/handler/redirect-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
Expand Down Expand Up @@ -125,7 +125,7 @@ class RedirectHandler {
}

if (!this.location) {
this.handler.onResponseStart?.(controller, statusCode, statusMessage, headers)
this.handler.onResponseStart?.(controller, statusCode, headers, statusMessage)
return
}

Expand Down
2 changes: 1 addition & 1 deletion lib/handler/unwrap-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion lib/handler/wrap-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/interceptor/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,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()
Expand Down
2 changes: 1 addition & 1 deletion types/dispatcher.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading