Skip to content

Commit 8e581ba

Browse files
committed
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 <mjkim610@gmail.com>
1 parent b63b419 commit 8e581ba

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

internal/runner/options.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package runner
22

33
import (
4+
"errors"
45
"math"
56
"os"
67
"path/filepath"
@@ -142,6 +143,10 @@ func ParseOptions() (*Options, error) {
142143
readFlagsConfig(flagSet, options.ConfigDir)
143144
}
144145

146+
if len(options.UpstreamHTTPProxies) > 0 && len(options.UpstreamSOCKS5Proxies) > 0 {
147+
return nil, errors.New("can't use upstream HTTP proxies and upstream SOCKS5 proxies at the same time")
148+
}
149+
145150
if cfgFile != "" {
146151
if !fileutil.FileExists(cfgFile) {
147152
gologger.Fatal().Msgf("given config file '%s' does not exist", cfgFile)

internal/runner/runner.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ func (r *Runner) Run() error {
112112

113113
if len(r.options.UpstreamHTTPProxies) > 0 {
114114
gologger.Info().Msgf("Using upstream HTTP proxies: %s\n", r.options.UpstreamHTTPProxies)
115-
} else if len(r.options.UpstreamSOCKS5Proxies) > 0 {
115+
}
116+
if len(r.options.UpstreamSOCKS5Proxies) > 0 {
116117
gologger.Info().Msgf("Using upstream SOCKS5 proxies: %s\n", r.options.UpstreamSOCKS5Proxies)
117118
}
118119

proxy.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,8 @@ func (p *Proxy) getRoundTripper() (http.RoundTripper, error) {
523523
roundtrip = &http.Transport{Proxy: func(req *http.Request) (*url.URL, error) {
524524
return url.Parse(p.rbHTTP.Next())
525525
}, TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}
526-
} else if len(p.options.UpstreamSOCKS5Proxies) > 0 {
526+
}
527+
if len(p.options.UpstreamSOCKS5Proxies) > 0 {
527528
// for each socks5 proxy create a dialer
528529
socks5Dialers := make(map[string]proxy.Dialer)
529530
for _, socks5Proxy := range p.options.UpstreamSOCKS5Proxies {

0 commit comments

Comments
 (0)