From abe6c1e3fc3fe5c2d849e73ce8db8a782eb12ea6 Mon Sep 17 00:00:00 2001 From: MJ Kim Date: Fri, 12 Sep 2025 15:28:57 +0900 Subject: [PATCH] Fail fast when both HTTP and SOCKS5 proxies are set The current implementation only supports either HTTP or SOCKS5 proxy, but this is not shown to the user clearly. If a user tries to set both HTTP and SOCKS5 proxies, fail fast with a clear msg. Signed-off-by: MJ Kim --- internal/runner/options.go | 5 +++++ internal/runner/runner.go | 3 ++- proxy.go | 3 ++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/internal/runner/options.go b/internal/runner/options.go index 9bdd93a..c7cd014 100644 --- a/internal/runner/options.go +++ b/internal/runner/options.go @@ -1,6 +1,7 @@ package runner import ( + "errors" "math" "os" "path/filepath" @@ -142,6 +143,10 @@ func ParseOptions() (*Options, error) { readFlagsConfig(flagSet, options.ConfigDir) } + if len(options.UpstreamHTTPProxies) > 0 && len(options.UpstreamSOCKS5Proxies) > 0 { + return nil, errors.New("can't use upstream HTTP proxies and upstream SOCKS5 proxies at the same time") + } + if cfgFile != "" { if !fileutil.FileExists(cfgFile) { gologger.Fatal().Msgf("given config file '%s' does not exist", cfgFile) diff --git a/internal/runner/runner.go b/internal/runner/runner.go index 6f27352..8f37b03 100644 --- a/internal/runner/runner.go +++ b/internal/runner/runner.go @@ -112,7 +112,8 @@ func (r *Runner) Run() error { if len(r.options.UpstreamHTTPProxies) > 0 { gologger.Info().Msgf("Using upstream HTTP proxies: %s\n", r.options.UpstreamHTTPProxies) - } else if len(r.options.UpstreamSOCKS5Proxies) > 0 { + } + if len(r.options.UpstreamSOCKS5Proxies) > 0 { gologger.Info().Msgf("Using upstream SOCKS5 proxies: %s\n", r.options.UpstreamSOCKS5Proxies) } diff --git a/proxy.go b/proxy.go index f46e26a..ff35e89 100644 --- a/proxy.go +++ b/proxy.go @@ -523,7 +523,8 @@ func (p *Proxy) getRoundTripper() (http.RoundTripper, error) { roundtrip = &http.Transport{Proxy: func(req *http.Request) (*url.URL, error) { return url.Parse(p.rbHTTP.Next()) }, TLSClientConfig: &tls.Config{InsecureSkipVerify: true}} - } else if len(p.options.UpstreamSOCKS5Proxies) > 0 { + } + if len(p.options.UpstreamSOCKS5Proxies) > 0 { // for each socks5 proxy create a dialer socks5Dialers := make(map[string]proxy.Dialer) for _, socks5Proxy := range p.options.UpstreamSOCKS5Proxies {