内置代理支持


🌐 Built-in Proxy Support

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

当 Node.js 创建全局代理时,如果环境变量 NODE_USE_ENV_PROXY 设置为 1 或启用了 --use-env-proxy,全局代理将使用 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.

要动态且全局地启用代理支持,请使用 http.setGlobalProxyFromEnv()

🌐 To enable proxy support dynamically and globally, use http.setGlobalProxyFromEnv().

自定义代理也可以通过在构建代理时传递 proxyEnv 选项来创建并支持代理。其值可以是 process.env,如果他们只想继承环境变量中的配置,或者是一个具有特定设置以覆盖环境的对象。

🌐 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.