Spaces:
Running
Running
File size: 963 Bytes
8a8fe1d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
import axios, {AxiosInstance, CreateAxiosDefaults} from "axios";
import HttpsProxyAgent from "https-proxy-agent";
import {SessionConstructorOptions} from "tls-client/dist/esm/types";
import {Session} from "tls-client/dist/esm/sessions";
import tlsClient from "tls-client";
export function CreateAxiosProxy(config: CreateAxiosDefaults, proxy?: string): AxiosInstance {
const createConfig = {...config};
const useProxy = process.env.http_proxy || proxy;
if (useProxy) {
createConfig.proxy = false;
createConfig.httpAgent = HttpsProxyAgent(useProxy);
createConfig.httpsAgent = HttpsProxyAgent(useProxy);
}
return axios.create(createConfig);
}
export function CreateTlsProxy(config: SessionConstructorOptions, proxy?: string): Session {
const client = new tlsClient.Session(config);
const useProxy = process.env.http_proxy || proxy;
if (useProxy) {
client.proxy = useProxy;
}
return client;
}
|