带有代理和证书的节点 httpAgent(带有 TLS 的 https-proxy-agent)

发布时间:2021-02-26 14:16

所以我试图在使用代理和 TLS 授权的节点测试 (AVA) 中进行调用。 我正在使用:

  • 打字稿:3.9.3
  • ts 节点:8.10.2
  • 轴心:0.21.1
  • https-proxy-agent: 5.0.0

到目前为止我学到了什么:

所以只是用一些代码来结束,这就是我想要做的,但我不知道如何实现:

const httpsProxyAgent = new HttpsProxyAgent({
        cert: this.cert,
        key: this.key,
        ca: this.ca,
        host: PROXY_HOST,
        port: PROXY_PORT,
      });
// then later
const config: AxiosRequestConfig = {
  httpsAgent: httpsProxyAgent,
  headers: { ... }
  proxy: false
};

虽然 HttpsProxyAgent 似乎扩展了 Agent 这些选项(证书部分)没有使用,我收到 UNABLE_TO_VERIFY_LEAF_SIGNATURE 错误,表明 ca 被忽略。 有谁知道如何向该代理提供这些证书? 我找不到任何答案。我不是节点专家,所以我可能错过了一些明显的东西。

提前致谢!

附注。我也试过这样Objects.assign()

// this proxy agent is working for sure (tested)
const httpsProxyAgent = new HttpsProxyAgent('http://proxy:1234');

// trying to assign certs after creating httpsProxyAgent
Object.assign(httpsAgent.options, {
  ca: this.ca,
  key: this.key,
  cert: this.cert
});

// then again passing it to AxiosRequestConfig.httpAgent and making a call

结果又是UNABLE_TO_VERIFY_LEAF_SIGNATURE

PSS。我见过这个 better-https-proxy-agent (git page) 似乎有解决方案,唯一的缺点是我看不到任何 TS 支持。

回答1
https-proxy-agent 相关推荐