{
  "type": "module",
  "source": "doc/api/api-envhttpproxyagent.md",
  "modules": [
    {
      "textRaw": "EnvHttpProxyAgent",
      "name": "envhttpproxyagent",
      "introduced_in": "v6.14.0",
      "type": "module",
      "stability": 2,
      "stabilityText": "Stable",
      "desc": "<p><code>EnvHttpProxyAgent</code> is a <a href=\"Dispatcher.html#class-dispatcher\"><code>Dispatcher</code></a> that reads its proxy configuration from\nthe <code>http_proxy</code>, <code>https_proxy</code>, and <code>no_proxy</code> environment variables and routes\nrequests through the appropriate proxy automatically. Import it from <code>undici</code>:</p>\n<pre><code class=\"language-mjs\">import { EnvHttpProxyAgent } from 'undici'\n</code></pre>\n<p>When <code>http_proxy</code> and <code>https_proxy</code> are both set, <code>http_proxy</code> is used for HTTP\nrequests and <code>https_proxy</code> is used for HTTPS requests. If only <code>http_proxy</code> is\nset, it is used for both HTTP and HTTPS requests. If only <code>https_proxy</code> is set,\nit is used only for HTTPS requests.</p>\n<p><code>no_proxy</code> is a comma- or space-separated list of hosts that must not be\nproxied. Each entry may include a leading dot or <code>*.</code> wildcard (for example\n<code>.example.com</code>) to match subdomains, and an optional <code>:port</code> suffix to restrict\nthe match to a specific port. A request bypasses the proxy when its host equals\nan entry or is a subdomain of one. Setting <code>no_proxy</code> to <code>*</code> bypasses the proxy\nfor every request.</p>\n<p>The uppercase variants <code>HTTP_PROXY</code>, <code>HTTPS_PROXY</code>, and <code>NO_PROXY</code> are also\nhonored. When both the lowercase and uppercase forms of a variable are set, the\nlowercase form takes precedence and the uppercase form is ignored. The <code>no_proxy</code>\nvalue is re-read from the environment on demand, so changes to it after the agent\nis created take effect on subsequent requests; this does not apply when <code>noProxy</code>\nis passed as an option.</p>",
      "classes": [
        {
          "textRaw": "Class: `EnvHttpProxyAgent`",
          "name": "EnvHttpProxyAgent",
          "type": "class",
          "meta": {
            "added": [
              "v6.14.0"
            ],
            "changes": []
          },
          "desc": "<ul>\n<li>Extends: <a href=\"Dispatcher.md#class-dispatcher\"><code>&#x3C;Dispatcher></code></a></li>\n</ul>",
          "signatures": [
            {
              "textRaw": "`new EnvHttpProxyAgent([options])`",
              "name": "EnvHttpProxyAgent",
              "type": "ctor",
              "meta": {
                "added": [
                  "v6.14.0"
                ],
                "changes": []
              },
              "params": [
                {
                  "textRaw": "`options` {EnvHttpProxyAgentOptions} Extends the `ProxyAgent` options (except `uri`). (optional)",
                  "name": "options",
                  "type": "EnvHttpProxyAgentOptions",
                  "desc": "Extends the `ProxyAgent` options (except `uri`). (optional)",
                  "options": [
                    {
                      "textRaw": "`httpProxy` {string} When set, overrides the `http_proxy` and `HTTP_PROXY` environment variables. (optional)",
                      "name": "httpProxy",
                      "type": "string",
                      "desc": "When set, overrides the `http_proxy` and `HTTP_PROXY` environment variables. (optional)"
                    },
                    {
                      "textRaw": "`httpsProxy` {string} When set, overrides the `https_proxy` and `HTTPS_PROXY` environment variables. (optional)",
                      "name": "httpsProxy",
                      "type": "string",
                      "desc": "When set, overrides the `https_proxy` and `HTTPS_PROXY` environment variables. (optional)"
                    },
                    {
                      "textRaw": "`noProxy` {string} When set, overrides the `no_proxy` and `NO_PROXY` environment variables. (optional)",
                      "name": "noProxy",
                      "type": "string",
                      "desc": "When set, overrides the `no_proxy` and `NO_PROXY` environment variables. (optional)"
                    }
                  ],
                  "optional": true
                }
              ],
              "return": {
                "textRaw": "Returns: {EnvHttpProxyAgent}",
                "name": "return",
                "type": "EnvHttpProxyAgent"
              },
              "desc": "<p>Creates a new <code>EnvHttpProxyAgent</code>. Any options other than <code>httpProxy</code>,\n<code>httpsProxy</code>, and <code>noProxy</code> are forwarded to the underlying <a href=\"Agent.html#class-agent\"><code>Agent</code></a> and\n<a href=\"ProxyAgent.html#class-proxyagent\"><code>ProxyAgent</code></a> instances. Constructing the agent only configures it; it does\nnot affect any request until it is registered as a dispatcher, either globally\nwith <code>setGlobalDispatcher()</code> or per-request through the <code>dispatcher</code> option.</p>\n<pre><code class=\"language-mjs\">import { EnvHttpProxyAgent } from 'undici'\n\nconst envHttpProxyAgent = new EnvHttpProxyAgent()\n// or, overriding the environment variables explicitly:\nconst envHttpProxyAgentWithOpts = new EnvHttpProxyAgent({\n  httpProxy: 'my.proxy.server:8080',\n  httpsProxy: 'my.proxy.server:8443',\n  noProxy: 'localhost'\n})\n</code></pre>",
              "modules": [
                {
                  "textRaw": "Example - Proxied `fetch()` with the global dispatcher",
                  "name": "example_-_proxied_`fetch()`_with_the_global_dispatcher",
                  "type": "module",
                  "desc": "<pre><code class=\"language-mjs\">import { setGlobalDispatcher, fetch, EnvHttpProxyAgent } from 'undici'\n\nconst envHttpProxyAgent = new EnvHttpProxyAgent()\nsetGlobalDispatcher(envHttpProxyAgent)\n\nconst response = await fetch('http://localhost:3000/foo')\n\nconsole.log('response received', response.status) // response received 200\n\nconst data = await response.json() // data { foo: 'bar' }\n</code></pre>",
                  "displayName": "Example - Proxied `fetch()` with the global dispatcher"
                },
                {
                  "textRaw": "Example - Proxied `request()` with the global dispatcher",
                  "name": "example_-_proxied_`request()`_with_the_global_dispatcher",
                  "type": "module",
                  "desc": "<pre><code class=\"language-mjs\">import { setGlobalDispatcher, request, EnvHttpProxyAgent } from 'undici'\n\nconst envHttpProxyAgent = new EnvHttpProxyAgent()\nsetGlobalDispatcher(envHttpProxyAgent)\n\nconst { statusCode, body } = await request('http://localhost:3000/foo')\n\nconsole.log('response received', statusCode) // response received 200\n\nfor await (const data of body) {\n  console.log('data', data.toString('utf8')) // data foo\n}\n</code></pre>",
                  "displayName": "Example - Proxied `request()` with the global dispatcher"
                },
                {
                  "textRaw": "Example - Proxied `request()` with a local dispatcher",
                  "name": "example_-_proxied_`request()`_with_a_local_dispatcher",
                  "type": "module",
                  "desc": "<pre><code class=\"language-mjs\">import { EnvHttpProxyAgent, request } from 'undici'\n\nconst envHttpProxyAgent = new EnvHttpProxyAgent()\n\nconst { statusCode, body } = await request('http://localhost:3000/foo', {\n  dispatcher: envHttpProxyAgent\n})\n\nconsole.log('response received', statusCode) // response received 200\n\nfor await (const data of body) {\n  console.log('data', data.toString('utf8')) // data foo\n}\n</code></pre>",
                  "displayName": "Example - Proxied `request()` with a local dispatcher"
                },
                {
                  "textRaw": "Example - Proxied `fetch()` with a local dispatcher",
                  "name": "example_-_proxied_`fetch()`_with_a_local_dispatcher",
                  "type": "module",
                  "desc": "<pre><code class=\"language-mjs\">import { EnvHttpProxyAgent, fetch } from 'undici'\n\nconst envHttpProxyAgent = new EnvHttpProxyAgent()\n\nconst response = await fetch('http://localhost:3000/foo', {\n  dispatcher: envHttpProxyAgent\n})\n\nconsole.log('response received', response.status) // response received 200\n\nconst data = await response.json() // data { foo: 'bar' }\n</code></pre>",
                  "displayName": "Example - Proxied `fetch()` with a local dispatcher"
                }
              ]
            }
          ],
          "methods": [
            {
              "textRaw": "`envHttpProxyAgent.dispatch(options, handler)`",
              "name": "dispatch",
              "type": "method",
              "meta": {
                "added": [
                  "v6.14.0"
                ],
                "changes": []
              },
              "signatures": [
                {
                  "params": [
                    {
                      "textRaw": "`options` {AgentDispatchOptions}",
                      "name": "options",
                      "type": "AgentDispatchOptions",
                      "options": [
                        {
                          "textRaw": "`origin` {string|URL}",
                          "name": "origin",
                          "type": "string|URL"
                        }
                      ]
                    },
                    {
                      "textRaw": "`handler` {DispatchHandler}",
                      "name": "handler",
                      "type": "DispatchHandler"
                    }
                  ],
                  "return": {
                    "textRaw": "Returns: {boolean}",
                    "name": "return",
                    "type": "boolean"
                  }
                }
              ],
              "desc": "<p>Dispatches a request through the proxy selected for <code>options.origin</code>. The origin's\nprotocol, host, and port are compared against the <code>no_proxy</code> configuration: when\nthe host should be proxied, the request is routed to the HTTPS proxy agent for\n<code>https:</code> origins or the HTTP proxy agent otherwise; when the host is excluded by\n<code>no_proxy</code>, the request is sent directly through a non-proxying <a href=\"Agent.html#class-agent\"><code>Agent</code></a>.</p>\n<p>This method is not normally called directly. Use the higher-level\n<a href=\"Dispatcher.html#class-dispatcher\"><code>Dispatcher</code></a> methods such as <a href=\"Dispatcher.html#dispatcherrequestoptions-callback\"><code>dispatcher.request()</code></a> or the top-level\n<code>request()</code> and <code>fetch()</code> helpers instead.</p>"
            }
          ]
        }
      ]
    }
  ]
}