feat: add reusable proxy configuration

This commit is contained in:
QiuSW
2026-07-25 17:04:26 +08:00
parent f13e06500c
commit 3a3c92c875
13 changed files with 772 additions and 48 deletions
+1 -26
View File
@@ -5,8 +5,6 @@ import (
"errors"
"fmt"
"io/fs"
"net"
"net/url"
"os"
"path/filepath"
"strconv"
@@ -92,10 +90,7 @@ func BuildArgs(spec domain.LaunchSpec) ([]string, error) {
if err != nil {
return nil, err
}
proxy, err := normalizeProxy(normalized.ProxyServer)
if err != nil {
return nil, err
}
proxy := normalized.ProxyServer
args := []string{
"--user-data-dir=" + normalized.UserDataDir,
"--no-first-run",
@@ -128,26 +123,6 @@ func BuildArgs(spec domain.LaunchSpec) ([]string, error) {
return args, nil
}
func normalizeProxy(value string) (string, error) {
proxy := strings.TrimSpace(value)
if proxy == "" {
return "", nil
}
parsed, err := url.Parse(proxy)
if err != nil || parsed.User != nil || parsed.Hostname() == "" || parsed.Port() == "" || parsed.Path != "" || parsed.RawQuery != "" || parsed.Fragment != "" {
return "", fmt.Errorf("%w: proxy must be scheme://host:port without credentials", domain.ErrInvalidLaunchSpec)
}
scheme := strings.ToLower(parsed.Scheme)
if scheme != "http" && scheme != "https" && scheme != "socks4" && scheme != "socks5" {
return "", fmt.Errorf("%w: unsupported proxy scheme", domain.ErrInvalidLaunchSpec)
}
port, err := strconv.Atoi(parsed.Port())
if err != nil || port < 1 || port > 65535 {
return "", fmt.Errorf("%w: proxy port out of range", domain.ErrInvalidLaunchSpec)
}
return scheme + "://" + net.JoinHostPort(strings.ToLower(parsed.Hostname()), strconv.Itoa(port)), nil
}
func validateExtraArg(value string) error {
arg := strings.TrimSpace(value)
if arg == "" || !strings.HasPrefix(arg, "--") {