mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-05-02 21:50:52 +00:00
fix normalize in different place
This commit is contained in:
parent
588ef60411
commit
56492be757
3 changed files with 33 additions and 18 deletions
|
|
@ -11,8 +11,13 @@
|
|||
* This function adds the "http://" prefix if missing, since HTTP proxies are
|
||||
* the most common default.
|
||||
*
|
||||
* Note: Only HTTP and HTTPS proxies are supported. SOCKS proxies (socks://,
|
||||
* socks4://, socks5://) are NOT supported because the underlying undici library
|
||||
* does not support them. See: https://github.com/nodejs/undici/issues/2224
|
||||
*
|
||||
* @param proxyUrl - The proxy URL to normalize
|
||||
* @returns The normalized proxy URL with protocol prefix, or undefined if input is undefined/empty
|
||||
* @throws Error if a SOCKS proxy URL is provided
|
||||
*/
|
||||
export function normalizeProxyUrl(
|
||||
proxyUrl: string | undefined,
|
||||
|
|
@ -27,11 +32,20 @@ export function normalizeProxyUrl(
|
|||
}
|
||||
|
||||
// Check if the URL already has a protocol prefix
|
||||
// Support http, https, socks, socks4, socks5 protocols
|
||||
if (/^(https?|socks[45]?):\/\//i.test(trimmed)) {
|
||||
// Only support http and https protocols (undici limitation)
|
||||
if (/^https?:\/\//i.test(trimmed)) {
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
// Reject SOCKS proxies - undici does not support them
|
||||
if (/^socks[45]?:\/\//i.test(trimmed)) {
|
||||
throw new Error(
|
||||
`SOCKS proxy is not supported. The underlying HTTP client (undici) only supports HTTP and HTTPS proxies. ` +
|
||||
`Please use an HTTP/HTTPS proxy instead, or set up a SOCKS-to-HTTP proxy converter. ` +
|
||||
`See: https://github.com/nodejs/undici/issues/2224`,
|
||||
);
|
||||
}
|
||||
|
||||
// Add http:// prefix for proxy URLs without protocol
|
||||
// HTTP is the default for most proxy configurations
|
||||
return `http://${trimmed}`;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue