Skip to content

Commit f294bd2

Browse files
committed
fixup
1 parent a3094ac commit f294bd2

17 files changed

+30
-22
lines changed

docs/docs/api/RedirectHandler.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Returns: `RedirectHandler`
1616

1717
### Parameters
1818

19-
- **dispatch** `(options: Dispatch.DispatchOptions, handlers: Dispatch.DispatchHandlers) => Promise<Dispatch.DispatchResponse>` (required) - Dispatch function to be called after every redirection.
19+
- **dispatch** `(options: Dispatch.DispatchOptions, handlers: Dispatch.DispatchHandler) => Promise<Dispatch.DispatchResponse>` (required) - Dispatch function to be called after every redirection.
2020
- **maxRedirections** `number` (required) - Maximum number of redirections allowed.
2121
- **opts** `object` (required) - Options for handling redirection.
2222
- **handler** `object` (required) - Handlers for different stages of the request lifecycle.

docs/docs/api/RetryHandler.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ It represents the retry state for a given request.
4343

4444
### Parameter `RetryHandlers`
4545

46-
- **dispatch** `(options: Dispatch.DispatchOptions, handlers: Dispatch.DispatchHandlers) => Promise<Dispatch.DispatchResponse>` (required) - Dispatch function to be called after every retry.
47-
- **handler** Extends [`Dispatch.DispatchHandlers`](/docs/docs/api/Dispatcher.md#dispatcherdispatchoptions-handler) (required) - Handler function to be called after the request is successful or the retries are exhausted.
46+
- **dispatch** `(options: Dispatch.DispatchOptions, handlers: Dispatch.DispatchHandler) => Promise<Dispatch.DispatchResponse>` (required) - Dispatch function to be called after every retry.
47+
- **handler** Extends [`Dispatch.DispatchHandler`](/docs/docs/api/Dispatcher.md#dispatcherdispatchoptions-handler) (required) - Handler function to be called after the request is successful or the retries are exhausted.
4848

4949
>__Note__: The `RetryHandler` does not retry over stateful bodies (e.g. streams, AsyncIterable) as those, once consumed, are left in a state that cannot be reutilized. For these situations the `RetryHandler` will identify
5050
>the body as stateful and will not retry the request rejecting with the error `UND_ERR_REQ_RETRY`.

lib/handler/cache-handler.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ class CacheHandler {
5252
this.#handler.onRequestStart?.(controller, context)
5353
}
5454

55+
onRequestUpgrade (controller, statusCode, headers, socket) {
56+
this.#handler.onRequestUpgrade?.(controller, statusCode, headers, socket)
57+
}
58+
5559
onResponseStart (
5660
controller,
5761
statusCode,

lib/handler/cache-revalidation-handler.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ class CacheRevalidationHandler {
4646
this.#context = context
4747
}
4848

49+
onRequestUpgrade (controller, statusCode, headers, socket) {
50+
this.#handler.onRequestUpgrade?.(controller, statusCode, headers, socket)
51+
}
52+
4953
onResponseStart (
5054
controller,
5155
statusCode,

lib/interceptor/cache.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ module.exports = (opts = {}) => {
267267
opts.body.on('error', () => {}).destroy()
268268
}
269269

270-
respondWithCachedValue(result, age)
270+
respondWithCachedValue(result, age, null)
271271
}
272272

273273
if (typeof result.then === 'function') {

test/types/client.test-d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ expectAssignable<Client>(new Client('', {
7373
expectAssignable<Dispatcher['dispatch']>(dispatcher)
7474
return (opts, handlers) => {
7575
expectAssignable<Dispatcher.DispatchOptions>(opts)
76-
expectAssignable<Dispatcher.DispatchHandlers>(handlers)
76+
expectAssignable<Dispatcher.DispatchHandler>(handlers)
7777
return dispatcher(opts, handlers)
7878
}
7979
}]

test/types/dispatcher.test-d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ expectAssignable<Dispatcher.ComposedDispatcher>(new Dispatcher().compose(
178178
expectAssignable<Dispatcher['dispatch']>(dispatcher)
179179
return (opts, handlers) => {
180180
expectAssignable<Dispatcher.DispatchOptions>(opts)
181-
expectAssignable<Dispatcher.DispatchHandlers>(handlers)
181+
expectAssignable<Dispatcher.DispatchHandler>(handlers)
182182
return dispatcher(opts, handlers)
183183
}
184184
}
@@ -188,15 +188,15 @@ expectAssignable<Dispatcher.ComposedDispatcher>(new Dispatcher().compose([
188188
expectAssignable<Dispatcher['dispatch']>(dispatcher)
189189
return (opts, handlers) => {
190190
expectAssignable<Dispatcher.DispatchOptions>(opts)
191-
expectAssignable<Dispatcher.DispatchHandlers>(handlers)
191+
expectAssignable<Dispatcher.DispatchHandler>(handlers)
192192
return dispatcher(opts, handlers)
193193
}
194194
},
195195
(dispatcher) => {
196196
expectAssignable<Dispatcher['dispatch']>(dispatcher)
197197
return (opts, handlers) => {
198198
expectAssignable<Dispatcher.DispatchOptions>(opts)
199-
expectAssignable<Dispatcher.DispatchHandlers>(handlers)
199+
expectAssignable<Dispatcher.DispatchHandler>(handlers)
200200
return dispatcher(opts, handlers)
201201
}
202202
}

test/types/index.test-d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ expectAssignable<Dispatcher.DispatcherComposeInterceptor>(Undici.interceptors.re
1717
expectAssignable<Dispatcher.DispatcherComposeInterceptor>(Undici.interceptors.cache())
1818

1919
const client = new Undici.Client('', {})
20-
const handler: Dispatcher.DispatchHandlers = {}
20+
const handler: Dispatcher.DispatchHandler = {}
2121

2222
const redirectHandler = new Undici.RedirectHandler(client, 10, {
2323
path: '/', method: 'GET'

types/agent.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ declare class Agent extends Dispatcher {
1111
/** `true` after `dispatcher.destroyed()` has been called or `dispatcher.close()` has been called and the dispatcher shutdown has completed. */
1212
destroyed: boolean
1313
/** Dispatches a request. */
14-
dispatch (options: Agent.DispatchOptions, handler: Dispatcher.DispatchHandlers): boolean
14+
dispatch (options: Agent.DispatchOptions, handler: Dispatcher.DispatchHandler): boolean
1515
}
1616

1717
declare namespace Agent {

types/dispatcher.d.ts

Lines changed: 1 addition & 1 deletion
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, headers: IncomingHttpHeaders): void;
229+
onResponseStart?(controller: DispatchController, statusCode: number, statusMessage: string | null, headers: IncomingHttpHeaders): 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)