diff --git a/xmpp.go b/xmpp.go index 6340b9c..64aed6f 100644 --- a/xmpp.go +++ b/xmpp.go @@ -68,6 +68,11 @@ func (c *Client) JID() string { return c.jid } +func containsIgnoreCase(s, substr string) bool { + s, substr = strings.ToUpper(s), strings.ToUpper(substr) + return strings.Contains(s, substr) +} + func connect(host, user, passwd string) (net.Conn, error) { addr := host @@ -81,16 +86,31 @@ func connect(host, user, passwd string) (net.Conn, error) { if len(a) == 1 { addr += ":5222" } + proxy := os.Getenv("HTTP_PROXY") if proxy == "" { proxy = os.Getenv("http_proxy") } + // test for no proxy + if proxy != "" { + noproxy := os.Getenv("no_proxy") + if noproxy != "" { + nplist := strings.Split(noproxy, ",") + for _, s := range nplist { + if containsIgnoreCase(addr, s) { + proxy = "" + break + } + } + } + } if proxy != "" { url, err := url.Parse(proxy) if err == nil { addr = url.Host } } + c, err := net.Dial("tcp", addr) if err != nil { return nil, err