Title: Make it possible to use Fetch with proxies or other agents · Issue #42814 · nodejs/node · GitHub
Open Graph Title: Make it possible to use Fetch with proxies or other agents · Issue #42814 · nodejs/node
X Title: Make it possible to use Fetch with proxies or other agents · Issue #42814 · nodejs/node
Description: What is the problem this feature will solve? The new fetch API as implemented cannot be used with an HTTP proxy, which is required for connectivity in many environments. For normal HTTP this is implemented via agents, but there's no way ...
Open Graph Description: What is the problem this feature will solve? The new fetch API as implemented cannot be used with an HTTP proxy, which is required for connectivity in many environments. For normal HTTP this is imp...
X Description: What is the problem this feature will solve? The new fetch API as implemented cannot be used with an HTTP proxy, which is required for connectivity in many environments. For normal HTTP this is imp...
Opengraph URL: https://github.com/nodejs/node/issues/42814
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Make it possible to use Fetch with proxies or other agents","articleBody":"### What is the problem this feature will solve?\n\nThe new fetch API as implemented cannot be used with an HTTP proxy, which is required for connectivity in many environments.\r\n\r\nFor normal HTTP this is implemented via agents, but there's no way to use any agents with this fetch API. Many of us working in environments with proxies use libraries like [global-agent](https://www.npmjs.com/package/global-agent) which set node's `globalAgent` to a proxy agent based on the system settings to automatically configure all libraries, but that doesn't work with fetch either.\r\n\r\nNotably, this means the docs are wrong right now, [when they say](https://nodejs.org/api/http.html#httpglobalagent):\r\n\r\n\u003e http.globalAgent: Global instance of Agent which is used as the default for all HTTP client requests.\r\n\r\nThis agent is not used for HTTP client requests if you use the fetch API.\r\n\r\nNode's fetch implementation comes from Undici, and although Undici doesn't offer an explicit way to set this per fetch request (see https://github.com/nodejs/undici/issues/1350) it does offer an agent-equivalent `dispatcher` option on all other request methods, and a [`setGlobalDispatcher`](https://github.com/nodejs/undici#undicisetglobaldispatcherdispatcher) method to configure a dispatcher globally (like node's `globalAgent`) which does work for fetch.\r\n\r\nThat means it is possible to use proxies with Undici's fetch right now, but not in Node as this isn't exposed anywhere (AFAICT).\n\n### What is the feature you are proposing to solve the problem?\n\n* Provide a way to specify a Node.js agent or a Undici dispatcher for a fetch request\r\n* Provide a way to set a global agent/dispatcher, which applies to all HTTP \u0026 fetch requests\r\n\r\nSince they're very closely related, it seems like it would be sensible to aim to move everything to either agents or dispatchers for all HTTP APIs in future. While fetch is experimental though it seems reasonable to me to implement this only with Undici's existing dispatchers for now and pick one direction or the other to commonize later.\n\n### What alternatives have you considered?\n\nAs far as I can tell, there's currently no alternative or workaround available to use proxies with fetch in Node. If you need to use an HTTP proxy for connectivity, the current fetch API is unusable.\r\n\r\nThis is particularly bad because some libraries that support both browsers \u0026 node will use the fetch global automatically when available or `node-fetch` otherwise (which uses `http` internally) for their requests. Although it used to be possible to use these libraries in a proxy environment by using global-agent or passing an agent explicitly, it's now impossible to use these libraries at all, because they use the new fetch global which ignores all agent configuration.","author":{"url":"https://github.com/pimterry","@type":"Person","name":"pimterry"},"datePublished":"2022-04-21T14:32:38.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":36},"url":"https://github.com/42814/node/issues/42814"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:3923e7a0-2013-e5f5-bad6-b9a0935142f5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A0A2:32C21D:1433E8E:1D632C6:6A4E457E |
| html-safe-nonce | ed6841578ec643b755bbbaf3a5d58b3740dc3624d961fce9aa8aedd7e775705d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMEEyOjMyQzIxRDoxNDMzRThFOjFENjMyQzY6NkE0RTQ1N0UiLCJ2aXNpdG9yX2lkIjoiNTI3MjI4NTgyMTc5MzA5Mjk5MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 654a9bcefea761ab8eac101ff317de500137a5f567ba615743b4a5645b81eaa5 |
| hovercard-subject-tag | issue:1211132441 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/42814/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b2775da4574d525dc49bb63cfdea079ae6b1199121b7e9aee50b7c895f1d282d/nodejs/node/issues/42814 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b2775da4574d525dc49bb63cfdea079ae6b1199121b7e9aee50b7c895f1d282d/nodejs/node/issues/42814 |
| og:image:alt | What is the problem this feature will solve? The new fetch API as implemented cannot be used with an HTTP proxy, which is required for connectivity in many environments. For normal HTTP this is imp... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | pimterry |
| hostname | github.com |
| expected-hostname | github.com |
| None | 030096ee0db095447bfe77409d33bfac127ca7128299c58deef27c52eaa1b1f0 |
| turbo-cache-control | no-preview |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9fabff9b8b127e686a3ec86f91422e818056ca2c |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width