-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: remove custom proxy handling #143
base: main
Are you sure you want to change the base?
Conversation
Undici has added native support for proxy handling, so it is no longer necessary for us to implement our own custom proxy handling.
47d08ea
to
98eac26
Compare
👋 @dmitrijrub @mikakesan Since you helped us test proxy functionality (#99) when we added support for it in #102, would you be willing to help us test this branch ( |
hi @parkerbxyz, what are the changes? should I just use |
Yes, exactly! 🙂 |
hmmm, looks like its failing
|
Noting this in case it is helpful later: nodejs/undici#1650 (comment) |
`EnvHttpProxyAgent` automatically reads the proxy configuration from the environment variables.
bbbe985
to
1f00388
Compare
Proxy support should be automatic
Thank you so much for testing that, @dmitrijrub! I've made some changes in hopes of fixing the failure you encountered. Would you mind testing again and letting us know how it goes, please? 🙏 |
@@ -1,41 +1,10 @@ | |||
import core from "@actions/core"; | |||
import { request } from "@octokit/request"; | |||
import { ProxyAgent, fetch as undiciFetch } from "undici"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we need to explicitly use EnvHttpProxyAgent
?
https://github.com/nodejs/undici/blob/7f635e51f6170f4b59abedc7cb45e6bcda7f056d/docs/docs/api/EnvHttpProxyAgent.md#L4
See this comment: nodejs/undici#1650 (comment)
I just wanted to leave that not for when we have another look at it, I don't have time to dig into it now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried that in 5cb4b2f, but several tests started failing as a result. After reading through nodejs/undici#2994, I got the impression it was unnecessary to do this.
Added
EnvHttpProxyAgent
and made it the default global dispatcher.
Automatically detect/support HTTP_PROXY, HTTPS_PROXY, & NO_PROXY
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super random drive-by comment. I got here from that issue. 😅
According to this commit, they ended up not using this as the default agent:
nodejs/undici@f31d3f9
Reasoning:
nodejs/undici#2994 (comment)
So it appears the PR description is wrong. Looks like they'll consider making it the default in a major release.
For now, I was able to get HTTPS_PROXY env variable to work via:
import { EnvHttpProxyAgent, setGlobalDispatcher } from "undici";
setGlobalDispatcher(new EnvHttpProxyAgent());
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @bruce-c-liu! I found some additional context here:
lib/request.js
Outdated
/* c8 ignore next */ | ||
request: proxyUrl ? { fetch: proxyFetch } : {}, | ||
request: { | ||
dispatcher: envHttpProxyAgent, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this will do anything. There is. no dispatch
option in options.request
, see all implemented options in https://github.com/octokit/request.js#request
What we have to do is to implement a fetch
wrapper
function fetchWithProxyAgent(url, options) {
return fetch(url, { ... options, dispatcher: envHttpProxyAgent })
}
And then use pass that custom fetch implementation as options.request.fetch
dispatcher: envHttpProxyAgent, | |
fetch: fetchWithProxyAgent, |
Tests are currently failing due to our current use of the global dispatcher in our tests and local dispatcher in the fetch method. The problem can be reproduced with the following example: import { EnvHttpProxyAgent, MockAgent, setGlobalDispatcher } from "undici";
const mockAgent = new MockAgent();
mockAgent.disableNetConnect();
setGlobalDispatcher(mockAgent);
const mockPool = mockAgent.get("https://example.test");
mockPool
.intercept({
path: `/`,
method: "GET",
})
.reply(200);
await fetch("https://example.test", {
// Comment out the following line to see the test succeed
dispatcher: new EnvHttpProxyAgent(),
});
console.log("OK"); The global dispatcher is not being used when a local dispatcher is set. We need to verify if this is a feature or a bug. |
|
Deno appears to have native proxy support: https://docs.deno.com/runtime/reference/env_variables/#special-environment-variables |
I'm down for using Deno instead of Node.js, as long as we still generate the built files with all dependencies and execute that code instead of loading dependencies dynamically at run time. |
I just received a really helpful PR here: peter-evans/create-pull-request#3475 And that lead me to realise that proxy support can be simplified to this: peter-evans/create-pull-request#3483 It passes the proxy support tests I have, so looks good. Just thought I would mention this in case it helps here. |
Undici has added native support for proxy handling, so it is no longer necessary for us to have our own custom proxy handling.
Reverts #102 and resolves #134.