-
Notifications
You must be signed in to change notification settings - Fork 63
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?
Changes from 15 commits
ae98c18
98eac26
fa33f86
5cb4b2f
28dfb1e
19e441f
1f00388
6aa1ac7
073d254
adf089d
4e61ab3
ed89981
02b34af
ff0675e
7a505dc
a0d0cbe
489a969
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,41 +1,17 @@ | ||||||
import core from "@actions/core"; | ||||||
import { request } from "@octokit/request"; | ||||||
import { ProxyAgent, fetch as undiciFetch } from "undici"; | ||||||
import { EnvHttpProxyAgent } from "undici"; | ||||||
|
||||||
const baseUrl = core.getInput("github-api-url").replace(/\/$/, ""); | ||||||
|
||||||
// https://docs.github.com/actions/hosting-your-own-runners/managing-self-hosted-runners/using-a-proxy-server-with-self-hosted-runners | ||||||
const proxyUrl = | ||||||
process.env.https_proxy || | ||||||
process.env.HTTPS_PROXY || | ||||||
process.env.http_proxy || | ||||||
process.env.HTTP_PROXY; | ||||||
|
||||||
/* c8 ignore start */ | ||||||
// Native support for proxies in Undici is under consideration: https://github.com/nodejs/undici/issues/1650 | ||||||
// Until then, we need to use a custom fetch function to add proxy support. | ||||||
const proxyFetch = (url, options) => { | ||||||
const urlHost = new URL(url).hostname; | ||||||
const noProxy = (process.env.no_proxy || process.env.NO_PROXY || "").split( | ||||||
"," | ||||||
); | ||||||
|
||||||
if (!noProxy.includes(urlHost)) { | ||||||
options = { | ||||||
...options, | ||||||
dispatcher: new ProxyAgent(String(proxyUrl)), | ||||||
}; | ||||||
} | ||||||
|
||||||
return undiciFetch(url, options); | ||||||
}; | ||||||
/* c8 ignore stop */ | ||||||
const envHttpProxyAgent = new EnvHttpProxyAgent(); | ||||||
|
||||||
export default request.defaults({ | ||||||
headers: { | ||||||
"user-agent": "actions/create-github-app-token", | ||||||
}, | ||||||
baseUrl, | ||||||
/* c8 ignore next */ | ||||||
request: proxyUrl ? { fetch: proxyFetch } : {}, | ||||||
request: { | ||||||
dispatcher: envHttpProxyAgent, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this will do anything. There is. no What we have to do is to implement a function fetchWithProxyAgent(url, options) {
return fetch(url, { ... options, dispatcher: envHttpProxyAgent })
} And then use pass that custom fetch implementation as
Suggested change
|
||||||
}, | ||||||
}); |
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.
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:
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:
https://github.com/nodejs/TSC/blob/41602b95211f30107696a007e5da45b9e933536c/meetings/2024-09-04.md?plain=1#L88-L115