mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-05-03 06:00:49 +00:00
fix proxy normalization
This commit is contained in:
parent
980604bccd
commit
bba3ab93b1
4 changed files with 122 additions and 2 deletions
37
packages/core/src/utils/proxyUtils.ts
Normal file
37
packages/core/src/utils/proxyUtils.ts
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/**
|
||||
* Copyright 2025 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* Normalizes a proxy URL to ensure it has a valid protocol prefix.
|
||||
*
|
||||
* Many proxy tools and environment variables provide proxy addresses without
|
||||
* a protocol prefix (e.g., "127.0.0.1:7860" instead of "http://127.0.0.1:7860").
|
||||
* This function adds the "http://" prefix if missing, since HTTP proxies are
|
||||
* the most common default.
|
||||
*
|
||||
* @param proxyUrl - The proxy URL to normalize
|
||||
* @returns The normalized proxy URL with protocol prefix, or undefined if input is undefined/empty
|
||||
*/
|
||||
export function normalizeProxyUrl(
|
||||
proxyUrl: string | undefined,
|
||||
): string | undefined {
|
||||
if (!proxyUrl) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const trimmed = proxyUrl.trim();
|
||||
if (!trimmed) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// Check if the URL already has a protocol prefix
|
||||
if (/^https?:\/\//i.test(trimmed)) {
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
// 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