From 206df5388033d8aefb727f5e4de709d4f701f5d4 Mon Sep 17 00:00:00 2001 From: Brian Dwyer Date: Wed, 13 Oct 2021 16:56:25 -0400 Subject: [PATCH] Adjust override logic to support suffixes --- pkg/gontlm-proxy.go | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/pkg/gontlm-proxy.go b/pkg/gontlm-proxy.go index ecaa303..7fe6643 100644 --- a/pkg/gontlm-proxy.go +++ b/pkg/gontlm-proxy.go @@ -99,13 +99,44 @@ func Run() { dctx, err, _ := dialerCacheGroup.Do(cacheKey, func() (pxyCtx interface{}, err error) { if ProxyOverrides != nil { - for _, host := range []string{addr, strings.Split(addr, ":")[0]} { + var detected bool + hosts := []string{addr, strings.Split(addr, ":")[0]} + // + // Exact Match + // + for _, host := range hosts { if pxy, ok := (*ProxyOverrides)[strings.ToLower(host)]; ok { + // If empty (nil) assume direct connection if pxy == nil { d := net.Dialer{} return d.DialContext, nil } + detected = true pxyUrl = pxy + break + } + } + + // + // Suffix Match + // + if !detected { + for _, host := range hosts { + for dns, pxy := range *ProxyOverrides { + if strings.HasSuffix(strings.ToLower(host), dns) { + // If empty (nil) assume direct connection + if pxy == nil { + d := net.Dialer{} + return d.DialContext, nil + } + detected = true + pxyUrl = pxy + break + } + } + if detected { + break + } } } }