mirror of https://github.com/certd/certd
perf: 系统设置中的代理设置优化为可全局生效,环境变量中的https_proxy设置将无效
parent
0ca61b4d99
commit
381a37fbaa
|
@ -202,6 +202,9 @@ export type HttpClient = {
|
||||||
request<D = any, R = any>(config: HttpRequestConfig<D>): Promise<HttpClientResponse<R>>;
|
request<D = any, R = any>(config: HttpRequestConfig<D>): Promise<HttpClientResponse<R>>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// const http_proxy_backup = process.env.HTTP_PROXY || process.env.http_proxy;
|
||||||
|
// const https_proxy_backup = process.env.HTTPS_PROXY || process.env.https_proxy;
|
||||||
|
|
||||||
export type CreateAgentOptions = {
|
export type CreateAgentOptions = {
|
||||||
httpProxy?: string;
|
httpProxy?: string;
|
||||||
httpsProxy?: string;
|
httpsProxy?: string;
|
||||||
|
@ -216,20 +219,28 @@ export function createAgent(opts: CreateAgentOptions = {}) {
|
||||||
);
|
);
|
||||||
|
|
||||||
let httpAgent, httpsAgent;
|
let httpAgent, httpsAgent;
|
||||||
const httpProxy = opts.httpProxy || process.env.HTTP_PROXY || process.env.http_proxy;
|
const httpProxy = opts.httpProxy;
|
||||||
if (httpProxy) {
|
if (httpProxy) {
|
||||||
|
process.env.HTTP_PROXY = httpProxy;
|
||||||
|
process.env.http_proxy = httpProxy;
|
||||||
logger.info('use httpProxy:', httpProxy);
|
logger.info('use httpProxy:', httpProxy);
|
||||||
httpAgent = new HttpProxyAgent(httpProxy, opts as any);
|
httpAgent = new HttpProxyAgent(httpProxy, opts as any);
|
||||||
merge(httpAgent.options, opts);
|
merge(httpAgent.options, opts);
|
||||||
} else {
|
} else {
|
||||||
|
process.env.HTTP_PROXY = '';
|
||||||
|
process.env.http_proxy = '';
|
||||||
httpAgent = new nodeHttp.Agent(opts);
|
httpAgent = new nodeHttp.Agent(opts);
|
||||||
}
|
}
|
||||||
const httpsProxy = opts.httpsProxy || process.env.HTTPS_PROXY || process.env.https_proxy;
|
const httpsProxy = opts.httpsProxy;
|
||||||
if (httpsProxy) {
|
if (httpsProxy) {
|
||||||
|
process.env.HTTPS_PROXY = httpProxy;
|
||||||
|
process.env.https_proxy = httpProxy;
|
||||||
logger.info('use httpsProxy:', httpsProxy);
|
logger.info('use httpsProxy:', httpsProxy);
|
||||||
httpsAgent = new HttpsProxyAgent(httpsProxy, opts as any);
|
httpsAgent = new HttpsProxyAgent(httpsProxy, opts as any);
|
||||||
merge(httpsAgent.options, opts);
|
merge(httpsAgent.options, opts);
|
||||||
} else {
|
} else {
|
||||||
|
process.env.HTTPS_PROXY = '';
|
||||||
|
process.env.https_proxy = '';
|
||||||
httpsAgent = new https.Agent(opts);
|
httpsAgent = new https.Agent(opts);
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
<a-input v-model:value="formState.private.httpsProxy" placeholder="http://192.168.1.2:18010/" />
|
<a-input v-model:value="formState.private.httpsProxy" placeholder="http://192.168.1.2:18010/" />
|
||||||
<a-button class="ml-5" type="primary" :loading="testProxyLoading" title="保存后,再点击测试" @click="testProxy">测试</a-button>
|
<a-button class="ml-5" type="primary" :loading="testProxyLoading" title="保存后,再点击测试" @click="testProxy">测试</a-button>
|
||||||
</div>
|
</div>
|
||||||
<div class="helper">一般这两个代理填一样的</div>
|
<div class="helper">一般这两个代理填一样的,保存后再测试</div>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
|
|
||||||
<a-form-item label="双栈网络" :name="['private', 'dnsResultOrder']">
|
<a-form-item label="双栈网络" :name="['private', 'dnsResultOrder']">
|
||||||
|
|
Loading…
Reference in New Issue