diff --git a/docs/docs/api/RedirectHandler.md b/docs/docs/api/RedirectHandler.md index 90a937e7c13..bb16284fff4 100644 --- a/docs/docs/api/RedirectHandler.md +++ b/docs/docs/api/RedirectHandler.md @@ -16,7 +16,7 @@ Returns: `RedirectHandler` ### Parameters -- **dispatch** `(options: Dispatch.DispatchOptions, handlers: Dispatch.DispatchHandlers) => Promise` (required) - Dispatch function to be called after every redirection. +- **dispatch** `(options: Dispatch.DispatchOptions, handlers: Dispatch.DispatchHandler) => Promise` (required) - Dispatch function to be called after every redirection. - **maxRedirections** `number` (required) - Maximum number of redirections allowed. - **opts** `object` (required) - Options for handling redirection. - **handler** `object` (required) - Handlers for different stages of the request lifecycle. diff --git a/docs/docs/api/RetryHandler.md b/docs/docs/api/RetryHandler.md index c24da75645c..04a621de33c 100644 --- a/docs/docs/api/RetryHandler.md +++ b/docs/docs/api/RetryHandler.md @@ -43,8 +43,8 @@ It represents the retry state for a given request. ### Parameter `RetryHandlers` -- **dispatch** `(options: Dispatch.DispatchOptions, handlers: Dispatch.DispatchHandlers) => Promise` (required) - Dispatch function to be called after every retry. -- **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. +- **dispatch** `(options: Dispatch.DispatchOptions, handlers: Dispatch.DispatchHandler) => Promise` (required) - Dispatch function to be called after every retry. +- **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. >__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 >the body as stateful and will not retry the request rejecting with the error `UND_ERR_REQ_RETRY`. diff --git a/lib/interceptor/cache.js b/lib/interceptor/cache.js index 91d5496f0c7..8da8468b04b 100644 --- a/lib/interceptor/cache.js +++ b/lib/interceptor/cache.js @@ -267,7 +267,7 @@ module.exports = (opts = {}) => { opts.body.on('error', () => {}).destroy() } - respondWithCachedValue(result, age) + respondWithCachedValue(result, age, null) } if (typeof result.then === 'function') { diff --git a/test/types/client.test-d.ts b/test/types/client.test-d.ts index 1c0f558a790..3e6d9c060f8 100644 --- a/test/types/client.test-d.ts +++ b/test/types/client.test-d.ts @@ -73,7 +73,7 @@ expectAssignable(new Client('', { expectAssignable(dispatcher) return (opts, handlers) => { expectAssignable(opts) - expectAssignable(handlers) + expectAssignable(handlers) return dispatcher(opts, handlers) } }] diff --git a/test/types/dispatcher.test-d.ts b/test/types/dispatcher.test-d.ts index 58dda692fdc..77f5320c1c4 100644 --- a/test/types/dispatcher.test-d.ts +++ b/test/types/dispatcher.test-d.ts @@ -178,7 +178,7 @@ expectAssignable(new Dispatcher().compose( expectAssignable(dispatcher) return (opts, handlers) => { expectAssignable(opts) - expectAssignable(handlers) + expectAssignable(handlers) return dispatcher(opts, handlers) } } @@ -188,7 +188,7 @@ expectAssignable(new Dispatcher().compose([ expectAssignable(dispatcher) return (opts, handlers) => { expectAssignable(opts) - expectAssignable(handlers) + expectAssignable(handlers) return dispatcher(opts, handlers) } }, @@ -196,7 +196,7 @@ expectAssignable(new Dispatcher().compose([ expectAssignable(dispatcher) return (opts, handlers) => { expectAssignable(opts) - expectAssignable(handlers) + expectAssignable(handlers) return dispatcher(opts, handlers) } } diff --git a/test/types/index.test-d.ts b/test/types/index.test-d.ts index 3dbfcf48fe5..fa33864641d 100644 --- a/test/types/index.test-d.ts +++ b/test/types/index.test-d.ts @@ -17,7 +17,7 @@ expectAssignable(Undici.interceptors.re expectAssignable(Undici.interceptors.cache()) const client = new Undici.Client('', {}) -const handler: Dispatcher.DispatchHandlers = {} +const handler: Dispatcher.DispatchHandler = {} const redirectHandler = new Undici.RedirectHandler(client, 10, { path: '/', method: 'GET' diff --git a/types/agent.d.ts b/types/agent.d.ts index 74d9d5493a4..ee313b5209b 100644 --- a/types/agent.d.ts +++ b/types/agent.d.ts @@ -11,7 +11,7 @@ declare class Agent extends Dispatcher { /** `true` after `dispatcher.destroyed()` has been called or `dispatcher.close()` has been called and the dispatcher shutdown has completed. */ destroyed: boolean /** Dispatches a request. */ - dispatch (options: Agent.DispatchOptions, handler: Dispatcher.DispatchHandlers): boolean + dispatch (options: Agent.DispatchOptions, handler: Dispatcher.DispatchHandler): boolean } declare namespace Agent { diff --git a/types/dispatcher.d.ts b/types/dispatcher.d.ts index 6b7c7e31b67..3c3a32c47f0 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, headers: IncomingHttpHeaders): void; + onResponseStart?(controller: DispatchController, statusCode: number, statusMessage: string | null, headers: IncomingHttpHeaders): void; onResponseData?(controller: DispatchController, chunk: Buffer): void; onResponseEnd?(controller: DispatchController, trailers: IncomingHttpHeaders): void; onResponseError?(controller: DispatchController, error: Error): void; diff --git a/types/env-http-proxy-agent.d.ts b/types/env-http-proxy-agent.d.ts index f5b1dc43060..28fbb846a35 100644 --- a/types/env-http-proxy-agent.d.ts +++ b/types/env-http-proxy-agent.d.ts @@ -6,7 +6,7 @@ export default EnvHttpProxyAgent declare class EnvHttpProxyAgent extends Dispatcher { constructor (opts?: EnvHttpProxyAgent.Options) - dispatch (options: Agent.DispatchOptions, handler: Dispatcher.DispatchHandlers): boolean + dispatch (options: Agent.DispatchOptions, handler: Dispatcher.DispatchHandler): boolean } declare namespace EnvHttpProxyAgent { diff --git a/types/handlers.d.ts b/types/handlers.d.ts index e95451540c9..a165f26c7d7 100644 --- a/types/handlers.d.ts +++ b/types/handlers.d.ts @@ -1,15 +1,15 @@ import Dispatcher from './dispatcher' -export declare class RedirectHandler implements Dispatcher.DispatchHandlers { +export declare class RedirectHandler implements Dispatcher.DispatchHandler { constructor ( dispatch: Dispatcher, maxRedirections: number, opts: Dispatcher.DispatchOptions, - handler: Dispatcher.DispatchHandlers, + handler: Dispatcher.DispatchHandler, redirectionLimitReached: boolean ) } -export declare class DecoratorHandler implements Dispatcher.DispatchHandlers { - constructor (handler: Dispatcher.DispatchHandlers) +export declare class DecoratorHandler implements Dispatcher.DispatchHandler { + constructor (handler: Dispatcher.DispatchHandler) } diff --git a/types/mock-agent.d.ts b/types/mock-agent.d.ts index 311b28b2db0..e92c7bea860 100644 --- a/types/mock-agent.d.ts +++ b/types/mock-agent.d.ts @@ -17,7 +17,7 @@ declare class MockAgent(origin: RegExp): TInterceptable get(origin: ((origin: string) => boolean)): TInterceptable /** Dispatches a mocked request. */ - dispatch (options: Agent.DispatchOptions, handler: Dispatcher.DispatchHandlers): boolean + dispatch (options: Agent.DispatchOptions, handler: Dispatcher.DispatchHandler): boolean /** Closes the mock agent and waits for registered mock pools and clients to also close before resolving. */ close (): Promise /** Disables mocking in MockAgent. */ diff --git a/types/mock-client.d.ts b/types/mock-client.d.ts index 704e48a6eec..88e16d9fb4f 100644 --- a/types/mock-client.d.ts +++ b/types/mock-client.d.ts @@ -11,7 +11,7 @@ declare class MockClient extends Client implements Interceptable { /** Intercepts any matching requests that use the same origin as this mock client. */ intercept (options: MockInterceptor.Options): MockInterceptor /** Dispatches a mocked request. */ - dispatch (options: Dispatcher.DispatchOptions, handlers: Dispatcher.DispatchHandlers): boolean + dispatch (options: Dispatcher.DispatchOptions, handlers: Dispatcher.DispatchHandler): boolean /** Closes the mock client and gracefully waits for enqueued requests to complete. */ close (): Promise } diff --git a/types/mock-pool.d.ts b/types/mock-pool.d.ts index 7ef52767366..5a9d9cb274f 100644 --- a/types/mock-pool.d.ts +++ b/types/mock-pool.d.ts @@ -11,7 +11,7 @@ declare class MockPool extends Pool implements Interceptable { /** Intercepts any matching requests that use the same origin as this mock pool. */ intercept (options: MockInterceptor.Options): MockInterceptor /** Dispatches a mocked request. */ - dispatch (options: Dispatcher.DispatchOptions, handlers: Dispatcher.DispatchHandlers): boolean + dispatch (options: Dispatcher.DispatchOptions, handlers: Dispatcher.DispatchHandler): boolean /** Closes the mock pool and gracefully waits for enqueued requests to complete. */ close (): Promise } diff --git a/types/proxy-agent.d.ts b/types/proxy-agent.d.ts index 5350dbc2e60..7d39f971c90 100644 --- a/types/proxy-agent.d.ts +++ b/types/proxy-agent.d.ts @@ -8,7 +8,7 @@ export default ProxyAgent declare class ProxyAgent extends Dispatcher { constructor (options: ProxyAgent.Options | string) - dispatch (options: Agent.DispatchOptions, handler: Dispatcher.DispatchHandlers): boolean + dispatch (options: Agent.DispatchOptions, handler: Dispatcher.DispatchHandler): boolean close (): Promise } diff --git a/types/retry-handler.d.ts b/types/retry-handler.d.ts index c4471cd6189..988e74b2b02 100644 --- a/types/retry-handler.d.ts +++ b/types/retry-handler.d.ts @@ -2,7 +2,7 @@ import Dispatcher from './dispatcher' export default RetryHandler -declare class RetryHandler implements Dispatcher.DispatchHandlers { +declare class RetryHandler implements Dispatcher.DispatchHandler { constructor ( options: Dispatcher.DispatchOptions & { retryOptions?: RetryHandler.RetryOptions; @@ -111,6 +111,6 @@ declare namespace RetryHandler { export interface RetryHandlers { dispatch: Dispatcher['dispatch']; - handler: Dispatcher.DispatchHandlers; + handler: Dispatcher.DispatchHandler; } }