Skip to content

Commit 02723d8

Browse files
committed
fix: pass the timeout to the resolveProtocol calls
1 parent d72dc83 commit 02723d8

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

src/hooks/browser-headers.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,13 @@ const getResolveProtocolFunction = (options: Options, proxyUrl: string | undefin
3939
}
4040

4141
if (proxyUrl) {
42-
return createResolveProtocol(proxyUrl, sessionData as any);
42+
return createResolveProtocol(proxyUrl, sessionData as any, options?.timeout?.connect ?? options?.timeout?.request);
4343
}
4444

45-
return http2.auto.resolveProtocol;
45+
return (...args: Parameters<typeof http2.auto.resolveProtocol>) => http2.auto.resolveProtocol({
46+
...args[0],
47+
timeout: options?.timeout?.connect ?? options?.timeout?.request,
48+
});
4649
};
4750

4851
export async function browserHeadersHook(options: Options): Promise<void> {

src/hooks/http2.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ export function http2Hook(options: Options): void {
1111
options.request = (url, requestOptions, callback) => {
1212
const typedRequestOptions = requestOptions as AutoRequestOptions;
1313
if (proxyUrl) {
14-
typedRequestOptions.resolveProtocol = createResolveProtocol(proxyUrl, sessionData as any);
14+
typedRequestOptions.resolveProtocol = createResolveProtocol(
15+
proxyUrl,
16+
sessionData as any,
17+
options?.timeout?.connect ?? options?.timeout?.request,
18+
);
1519
}
1620

1721
return auto(url, typedRequestOptions, callback);

src/resolve-protocol.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export interface ProtocolCache {
7373
resolveAlpnQueue?: typeof defaults.resolveAlpnQueue;
7474
}
7575

76-
export const createResolveProtocol = (proxyUrl: string, sessionData?: ProtocolCache): ResolveProtocolFunction => {
76+
export const createResolveProtocol = (proxyUrl: string, sessionData?: ProtocolCache, timeout?: number): ResolveProtocolFunction => {
7777
let { protocolCache, resolveAlpnQueue } = defaults;
7878

7979
if (sessionData) {
@@ -89,9 +89,14 @@ export const createResolveProtocol = (proxyUrl: string, sessionData?: ProtocolCa
8989
return connect(proxyUrl, pOptions, pCallback);
9090
};
9191

92-
return auto.createResolveProtocol(
92+
const resolveProtocol: ResolveProtocolFunction = auto.createResolveProtocol(
9393
protocolCache as unknown as Map<string, string>,
9494
resolveAlpnQueue,
9595
connectWithProxy,
9696
);
97+
98+
return async (...args: Parameters<ResolveProtocolFunction>) => resolveProtocol({
99+
...args[0],
100+
timeout,
101+
});
97102
};

0 commit comments

Comments
 (0)