@@ -7,8 +7,6 @@ import { EventEmitter } from "node:events";
77import type { Stream } from "node:stream" ;
88import debug from "debug" ;
99import { toURL } from "./common" ;
10- import type { Agent , Dispatcher } from "undici" ;
11- import { Agent as UndiciAgent , interceptors } from "undici" ;
1210
1311const log = debug ( "http-proxy-3" ) ;
1412
@@ -95,28 +93,30 @@ export interface ServerOptions {
9593 */
9694 ca ?: string ;
9795 /** Enable undici for HTTP/2 support. Set to true for defaults, or provide custom configuration. */
98- fetch ?: boolean | FetchOptions ;
96+ fetch ?: boolean | FetchOptions ;
9997}
10098
99+ export type Dispatcher = RequestInit [ "dispatcher" ] ;
100+
101101export interface FetchOptions {
102- /** Undici Agent configuration */
103- dispatcher ?: Dispatcher ;
104- /** Undici request options */
105- requestOptions ?: RequestInit ;
106- /** Called before making the undici request */
107- onBeforeRequest ?: (
108- requestOptions : RequestInit ,
109- req : http . IncomingMessage ,
110- res : http . ServerResponse ,
111- options : NormalizedServerOptions ,
112- ) => void | Promise < void > ;
113- /** Called after receiving the undici response */
114- onAfterResponse ?: (
115- response : Response ,
116- req : http . IncomingMessage ,
117- res : http . ServerResponse ,
118- options : NormalizedServerOptions ,
119- ) => void | Promise < void > ;
102+ /** Undici Agent configuration */
103+ dispatcher ?: Dispatcher ;
104+ /** Undici request options */
105+ requestOptions ?: RequestInit ;
106+ /** Called before making the undici request */
107+ onBeforeRequest ?: (
108+ requestOptions : RequestInit ,
109+ req : http . IncomingMessage ,
110+ res : http . ServerResponse ,
111+ options : NormalizedServerOptions ,
112+ ) => void | Promise < void > ;
113+ /** Called after receiving the undici response */
114+ onAfterResponse ?: (
115+ response : Response ,
116+ req : http . IncomingMessage ,
117+ res : http . ServerResponse ,
118+ options : NormalizedServerOptions ,
119+ ) => void | Promise < void > ;
120120}
121121
122122
@@ -265,7 +265,7 @@ export class ProxyServer<TIncomingMessage extends typeof http.IncomingMessage =
265265 this . webPasses = Object . values ( WEB_PASSES ) as Array < PassFunctions < TIncomingMessage , TServerResponse , TError > [ 'web' ] > ;
266266 this . wsPasses = Object . values ( WS_PASSES ) as Array < PassFunctions < TIncomingMessage , TServerResponse , TError > [ 'ws' ] > ;
267267 this . on ( "error" , this . onError ) ;
268- }
268+ }
269269
270270 /**
271271 * Creates the proxy server with specified options.
0 commit comments