-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Fix merge #2155
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 merge #2155
Changes from all commits
82c0ead
6ad33df
8775cdf
dc53028
501b06d
d6834c8
bdd9257
8468690
5254928
d48fbc3
3454bec
4a38e50
3818313
df20c5f
2d14c88
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,8 @@ | ||||||||||||||
| import { HttpsProxyAgent } from 'https-proxy-agent'; | ||||||||||||||
| import { SocksProxyAgent } from 'socks-proxy-agent'; | ||||||||||||||
|
|
||||||||||||||
| import { ProxyAgent } from 'undici' | ||||||||||||||
|
|
||||||||||||||
| type Proxy = { | ||||||||||||||
| host: string; | ||||||||||||||
| password?: string; | ||||||||||||||
|
|
@@ -42,3 +44,40 @@ | |||||||||||||
|
|
||||||||||||||
| return selectProxyAgent(proxyUrl); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| export function makeProxyAgentUndici(proxy: Proxy | string): ProxyAgent { | ||||||||||||||
| let proxyUrl: string | ||||||||||||||
| let protocol: string | ||||||||||||||
|
|
||||||||||||||
| if (typeof proxy === 'string') { | ||||||||||||||
| const url = new URL(proxy) | ||||||||||||||
| protocol = url.protocol.replace(':', '') | ||||||||||||||
| proxyUrl = proxy | ||||||||||||||
| } else { | ||||||||||||||
| const { host, password, port, protocol: proto, username } = proxy | ||||||||||||||
| protocol = (proto || 'http').replace(':', '') | ||||||||||||||
|
|
||||||||||||||
| if (protocol === 'socks') { | ||||||||||||||
| protocol = 'socks5' | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| const auth = username && password ? `${username}:${password}@` : '' | ||||||||||||||
| proxyUrl = `${protocol}://${auth}${host}:${port}` | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| const PROXY_HTTP_PROTOCOL = 'http' | ||||||||||||||
| const PROXY_HTTPS_PROTOCOL = 'https' | ||||||||||||||
| const PROXY_SOCKS4_PROTOCOL = 'socks4' | ||||||||||||||
| const PROXY_SOCKS5_PROTOCOL = 'socks5' | ||||||||||||||
|
|
||||||||||||||
| switch (protocol) { | ||||||||||||||
| case PROXY_HTTP_PROTOCOL: | ||||||||||||||
| case PROXY_HTTPS_PROTOCOL: | ||||||||||||||
| case PROXY_SOCKS4_PROTOCOL: | ||||||||||||||
| case PROXY_SOCKS5_PROTOCOL: | ||||||||||||||
| return new ProxyAgent(proxyUrl) | ||||||||||||||
|
|
||||||||||||||
| default: | ||||||||||||||
| throw new Error(`Unsupported proxy protocol: ${protocol}`) | ||||||||||||||
|
Comment on lines
+80
to
+81
Contributor
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. suggestion: Error message for unsupported protocol could be more informative. Including the full proxy input in the error message will make it easier to trace issues when user input is involved.
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.
suggestion: Protocol normalization for 'socks' is hardcoded to 'socks5'.
Some proxies use 'socks4', so please handle 'socks4' explicitly or document that 'socks' defaults to 'socks5'.