Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pass the timeout to the resolveProtocol calls #131

Merged
merged 2 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/hooks/browser-headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@ const getResolveProtocolFunction = (options: Options, proxyUrl: string | undefin
}

if (proxyUrl) {
return createResolveProtocol(proxyUrl, sessionData as any);
return createResolveProtocol(proxyUrl, sessionData as any, Math.min(options?.timeout?.connect ?? 60_000, options?.timeout?.request ?? 60_000));
}

return http2.auto.resolveProtocol;
return (...args: Parameters<typeof http2.auto.resolveProtocol>) => http2.auto.resolveProtocol({
...args[0],
timeout: Math.min(options?.timeout?.connect ?? 60_000, options?.timeout?.request ?? 60_000),
});
};

export async function browserHeadersHook(options: Options): Promise<void> {
Expand Down
6 changes: 5 additions & 1 deletion src/hooks/http2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ export function http2Hook(options: Options): void {
options.request = (url, requestOptions, callback) => {
const typedRequestOptions = requestOptions as AutoRequestOptions;
if (proxyUrl) {
typedRequestOptions.resolveProtocol = createResolveProtocol(proxyUrl, sessionData as any);
typedRequestOptions.resolveProtocol = createResolveProtocol(
proxyUrl,
sessionData as any,
Math.min(options?.timeout?.connect ?? 60_000, options?.timeout?.request ?? 60_000),
);
}

return auto(url, typedRequestOptions, callback);
Expand Down
9 changes: 7 additions & 2 deletions src/resolve-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export interface ProtocolCache {
resolveAlpnQueue?: typeof defaults.resolveAlpnQueue;
}

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

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

return auto.createResolveProtocol(
const resolveProtocol: ResolveProtocolFunction = auto.createResolveProtocol(
protocolCache as unknown as Map<string, string>,
resolveAlpnQueue,
connectWithProxy,
);

return async (...args: Parameters<ResolveProtocolFunction>) => resolveProtocol({
...args[0],
timeout,
});
};
Loading