内置代理支持


【Built-in Proxy Support】

稳定性: 1.1 - 处于活跃开发中

当 Node.js 创建全局代理时,如果 NODE_USE_ENV_PROXY 环境变量被设置为 1 或启用了 --use-env-proxy,全局代理将以 proxyEnv: process.env 构建,从而根据环境变量启用代理支持。通过在构建代理时传入 proxyEnv 选项,也可以创建具有代理支持的自定义代理。如果想要继承环境变量中的配置,该值可以设为 process.env,也可以是一个对象,用于覆盖环境变量的特定设置。

【When Node.js creates the global agent, if the NODE_USE_ENV_PROXY environment variable is set to 1 or --use-env-proxy is enabled, the global agent will be constructed with proxyEnv: process.env, enabling proxy support based on the environment variables. Custom agents can also be created with proxy support by passing a proxyEnv option when constructing the agent. The value can be process.env if they just want to inherit the configuration from the environment variables, or an object with specific setting overriding the environment.】

以下会检查 proxyEnv 的属性以配置代理支持。

【The following properties of the proxyEnv are checked to configure proxy support.】

  • HTTP_PROXYhttp_proxy:HTTP 请求的代理服务器 URL。如果两者都设置了,http_proxy 优先。
  • HTTPS_PROXYhttps_proxy:用于 HTTPS 请求的代理服务器 URL。如果两者都设置了,https_proxy 优先。
  • NO_PROXYno_proxy:以逗号分隔的要绕过代理的主机列表。如果两者都设置了,no_proxy 优先。

如果请求是向 Unix 域套接字发送的,则代理设置将被忽略。

【If the request is made to a Unix domain socket, the proxy settings will be ignored.】