Allow connecting via proxy

This commit is contained in:
J.P. Neverwas 2021-07-03 06:59:00 -07:00
parent 35410aa86c
commit 272c4d1650
3 changed files with 17 additions and 7 deletions

5
go.mod
View File

@ -2,4 +2,7 @@ module github.com/thoj/go-ircevent
go 1.12 go 1.12
require golang.org/x/text v0.3.2 require (
golang.org/x/net v0.0.0-20210614182718-04defd469f4e
golang.org/x/text v0.3.6
)

7
go.sum
View File

@ -1,3 +1,10 @@
golang.org/x/net v0.0.0-20210614182718-04defd469f4e h1:XpT3nA5TvE525Ne3hInMh6+GETgn27Zfm9dxsThnX2Q=
golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

12
irc.go
View File

@ -31,6 +31,7 @@ import (
"strings" "strings"
"time" "time"
"golang.org/x/net/proxy"
"golang.org/x/text/encoding" "golang.org/x/text/encoding"
) )
@ -461,15 +462,14 @@ func (irc *Connection) Connect(server string) error {
return errors.New("empty 'user'") return errors.New("empty 'user'")
} }
if irc.UseTLS { dialer := proxy.FromEnvironmentUsing(&net.Dialer{Timeout: irc.Timeout})
dialer := &net.Dialer{Timeout: irc.Timeout} irc.socket, err = dialer.Dial("tcp", irc.Server)
irc.socket, err = tls.DialWithDialer(dialer, "tcp", irc.Server, irc.TLSConfig)
} else {
irc.socket, err = net.DialTimeout("tcp", irc.Server, irc.Timeout)
}
if err != nil { if err != nil {
return err return err
} }
if irc.UseTLS {
irc.socket = tls.Client(irc.socket, irc.TLSConfig)
}
if irc.Encoding == nil { if irc.Encoding == nil {
irc.Encoding = encoding.Nop irc.Encoding = encoding.Nop