clean up getProxy logic
This commit is contained in:
parent
bfe8199fe3
commit
b0cc911cf9
2 changed files with 13 additions and 5 deletions
|
|
@ -5,7 +5,7 @@ import { HttpsProxyAgent } from "https-proxy-agent";
|
|||
import { BodyInit, RequestInit, Response } from "node-fetch";
|
||||
import { getAgentOptions } from "./getAgentOptions.js";
|
||||
import fetch from "./node-fetch-patch.js";
|
||||
import { getProxyFromEnv, shouldBypassProxy } from "./util.js";
|
||||
import { getProxy, shouldBypassProxy } from "./util.js";
|
||||
|
||||
const { http, https } = (followRedirects as any).default;
|
||||
|
||||
|
|
@ -92,10 +92,7 @@ export async function fetchwithRequestOptions(
|
|||
const agentOptions = getAgentOptions(requestOptions);
|
||||
|
||||
// Get proxy from options or environment variables
|
||||
let proxy = requestOptions?.proxy;
|
||||
if (!proxy) {
|
||||
proxy = getProxyFromEnv(url.protocol);
|
||||
}
|
||||
const proxy = getProxy(url.protocol, requestOptions);
|
||||
|
||||
// Check if should bypass proxy based on requestOptions or NO_PROXY env var
|
||||
const shouldBypass = shouldBypassProxy(url.hostname, requestOptions);
|
||||
|
|
|
|||
|
|
@ -18,6 +18,17 @@ export function getProxyFromEnv(protocol: string): string | undefined {
|
|||
}
|
||||
}
|
||||
|
||||
// Note that request options proxy (per model) takes precedence over environment variables
|
||||
export function getProxy(
|
||||
protocol: string,
|
||||
requestOptions?: RequestOptions,
|
||||
): string | undefined {
|
||||
if (requestOptions?.proxy) {
|
||||
return requestOptions.proxy;
|
||||
}
|
||||
return getProxyFromEnv(protocol);
|
||||
}
|
||||
|
||||
export function getEnvNoProxyPatterns(): string[] {
|
||||
const envValue = process.env.NO_PROXY || process.env.no_proxy;
|
||||
if (envValue) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue