MCPcopy Create free account
hub / github.com/ChatLab/ChatLab / validateProxyUrl

Function validateProxyUrl

apps/desktop/main/network/proxy.ts:103–120  ·  view source on GitHub ↗
(url: string)

Source from the content-addressed store, hash-verified

101 * 验证代理 URL 格式
102 */
103export function validateProxyUrl(url: string): { valid: boolean; error?: string } {
104 if (!url) {
105 return { valid: false, error: '代理地址不能为空' }
106 }
107
108 try {
109 const parsed = new URL(url)
110 if (!['http:', 'https:'].includes(parsed.protocol)) {
111 return { valid: false, error: '仅支持 http:// 或 https:// 协议' }
112 }
113 if (!parsed.hostname) {
114 return { valid: false, error: '代理地址格式无效' }
115 }
116 return { valid: true }
117 } catch {
118 return { valid: false, error: '代理地址格式无效,请使用 http://host:port 格式' }
119 }
120}
121
122/**
123 * 将代理设置应用到 Electron session

Callers 5

registerNetworkHandlersFunction · 0.90
testProxyConnectionFunction · 0.85
getActiveProxyUrlFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected