From a13203fb3f48c427d0d81a504912248dcc07df1a Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Thu, 3 Oct 2024 22:03:20 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=9F=90=E4=BA=9B?= =?UTF-8?q?=E4=BB=A3=E7=90=86=E6=83=85=E5=86=B5=E4=B8=8B=20=E6=8A=A5=20400?= =?UTF-8?q?=20The=20plain=20HTTP=20request=20was=20sent=20to=20HTTPS=20por?= =?UTF-8?q?t=20use=20proxy=20=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/pipeline/src/utils/util.request.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/core/pipeline/src/utils/util.request.ts b/packages/core/pipeline/src/utils/util.request.ts index b5c341c0..71d654f4 100644 --- a/packages/core/pipeline/src/utils/util.request.ts +++ b/packages/core/pipeline/src/utils/util.request.ts @@ -4,6 +4,7 @@ import { Logger } from "log4js"; import { HttpProxyAgent } from "http-proxy-agent"; import { HttpsProxyAgent } from "https-proxy-agent"; import nodeHttp from "http"; +import * as https from "node:https"; export class HttpError extends Error { status?: number; statusText?: string; @@ -17,7 +18,7 @@ export class HttpError extends Error { } super(error.message); - if (error?.message?.indexOf("ssl3_get_record:wrong version number") > -1) { + if (error?.message?.indexOf("ssl3_get_record:wrong version number") >= 0) { this.message = "http协议错误,服务端要求http协议,请检查是否使用了https请求"; } @@ -69,7 +70,7 @@ export function createAxiosService({ logger }: { logger: Logger }) { delete config.skipSslVerify; config.httpsAgent = agents.httpsAgent; config.httpAgent = agents.httpAgent; - + config.proxy = false; //必须 否则还会走一层代理, return config; }, (error: Error) => { @@ -154,13 +155,18 @@ export function createAgent(opts: nodeHttp.AgentOptions = {}) { let httpAgent, httpsAgent; const httpProxy = process.env.HTTP_PROXY || process.env.http_proxy; if (httpProxy) { + logger.info("use httpProxy:", httpProxy); httpAgent = new HttpProxyAgent(httpProxy, opts as any); + } else { + httpAgent = new nodeHttp.Agent(opts); } const httpsProxy = process.env.HTTPS_PROXY || process.env.https_proxy; if (httpsProxy) { + logger.info("use httpsProxy:", httpsProxy); httpsAgent = new HttpsProxyAgent(httpsProxy, opts as any); + } else { + httpsAgent = new https.Agent(opts); } - return { httpAgent, httpsAgent,