Skip to content

Commit 20b235c

Browse files
committed
fixup
1 parent ef233af commit 20b235c

File tree

4 files changed

+9
-10
lines changed

4 files changed

+9
-10
lines changed

docs/docs/api/Dispatcher.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,12 @@ Returns: `Boolean` - `false` if dispatcher is busy and further dispatch calls wo
205205

206206
#### Parameter: `DispatchHandler`
207207

208-
* **onConnect** `(abort: () => void, 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.
209-
* **onError** `(error: Error) => void` - Invoked when an error has occurred. May not throw.
210-
* **onUpgrade** `(statusCode: number, headers: Buffer[], socket: Duplex) => void` (optional) - Invoked when request is upgraded. Required if `DispatchOptions.upgrade` is defined or `DispatchOptions.method === 'CONNECT'`.
211-
* **onResponseStarted** `() => void` (optional) - Invoked when response is received, before headers have been read.
212-
* **onHeaders** `(statusCode: number, headers: Buffer[], resume: () => void, statusText: string) => boolean` - Invoked when statusCode and headers have been received. May be invoked multiple times due to 1xx informational headers. Not required for `upgrade` requests.
213-
* **onData** `(chunk: Buffer) => boolean` - Invoked when response payload data is received. Not required for `upgrade` requests.
214-
* **onComplete** `(trailers: Buffer[]) => void` - Invoked when response payload and trailers have been received and the request has completed. Not required for `upgrade` requests.
215-
* **onBodySent** `(chunk: string | Buffer | Uint8Array) => void` - Invoked when a body chunk is sent to the server. Not required. For a stream or iterable body this will be invoked for every chunk. For other body types, it will be invoked once after the body is sent.
208+
* **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.
209+
* **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 []>) => boolean` - Invoked when statusCode and headers have been received. May be invoked multiple times due to 1xx informational headers. Not required for `upgrade` requests.
211+
* **onResponseData** `(controller: DispatchController, chunk: Buffer) => boolean` - Invoked when response payload data is received. Not required for `upgrade` requests.
212+
* **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.
213+
* **onResponseError** `(error: Error) => void` - Invoked when an error has occurred. May not throw.
216214

217215
#### Example 1 - Dispatch GET request
218216

lib/handler/unwrap-handler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ module.exports = class UnwrapHandler {
6868
}
6969

7070
onUpgrade (statusCode, rawHeaders, socket) {
71-
this.#handler.onRequestUpgrade?.(statusCode, parseHeaders(rawHeaders), socket)
71+
this.#handler.onRequestUpgrade?.(this.#controller, statusCode, parseHeaders(rawHeaders), socket)
7272
}
7373

7474
onHeaders (statusCode, rawHeaders, resume, statusMessage) {

lib/handler/wrap-handler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ module.exports = class WrapHandler {
5050
this.#handler.onConnect?.((reason) => controller.abort(reason), context)
5151
}
5252

53-
onRequestUpgrade (statusCode, headers, socket) {
53+
onRequestUpgrade (controller, statusCode, headers, socket) {
5454
const rawHeaders = []
5555
for (const [key, val] of Object.entries(headers)) {
5656
// TODO (fix): What if val is Array

types/dispatcher.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ declare namespace Dispatcher {
225225

226226
export interface DispatchHandler {
227227
onRequestStart?(controller: DispatchController, context: any)
228+
onRequestUpgrade?(controller: DispatchController, statusCode: number, headers: IncomingHttpHeaders, socket: Duplex): void;
228229
onResponseStart?(controller: DispatchController, statusCode: number, statusMessage?: string, headers: IncomingHttpHeaders)
229230
onResponseData?(controller: DispatchController, chunk: Buffer)
230231
onResponseEnd?(controller: DispatchController, trailers: IncomingHttpHeaders)

0 commit comments

Comments
 (0)