Skip to content

Commit

Permalink
Adjust override logic to support suffixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bdwyertech committed Oct 13, 2021
1 parent ea6088f commit 206df53
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion pkg/gontlm-proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
}
Expand Down

0 comments on commit 206df53

Please sign in to comment.