From abbcd1f43662abdc55ca30acf003ca4c06d6f1c0 Mon Sep 17 00:00:00 2001 From: Audrius Butkevicius Date: Tue, 13 Oct 2015 19:52:22 +0100 Subject: [PATCH] Patch up HTTP clients --- cmd/syncthing/main.go | 3 +++ lib/dialer/dialer.go | 7 +++++++ lib/discover/global.go | 5 +++++ lib/rc/rc.go | 3 +++ lib/upgrade/upgrade_supported.go | 3 +++ 5 files changed, 21 insertions(+) diff --git a/cmd/syncthing/main.go b/cmd/syncthing/main.go index ff707b8b8..fcf4c7fe1 100644 --- a/cmd/syncthing/main.go +++ b/cmd/syncthing/main.go @@ -30,6 +30,7 @@ import ( "github.com/syncthing/syncthing/lib/config" "github.com/syncthing/syncthing/lib/connections" "github.com/syncthing/syncthing/lib/db" + "github.com/syncthing/syncthing/lib/dialer" "github.com/syncthing/syncthing/lib/discover" "github.com/syncthing/syncthing/lib/events" "github.com/syncthing/syncthing/lib/logger" @@ -432,6 +433,8 @@ func upgradeViaRest() error { r.Header.Set("X-API-Key", cfg.GUI().APIKey) tr := &http.Transport{ + Dial: dialer.Dial, + Proxy: http.ProxyFromEnvironment, TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, } client := &http.Client{ diff --git a/lib/dialer/dialer.go b/lib/dialer/dialer.go index 7d9d5b430..584a26829 100644 --- a/lib/dialer/dialer.go +++ b/lib/dialer/dialer.go @@ -8,6 +8,7 @@ package dialer import ( "net" + "net/http" "os" "strings" "time" @@ -26,6 +27,12 @@ var ( func init() { l.SetDebug("dialer", strings.Contains(os.Getenv("STTRACE"), "dialer") || os.Getenv("STTRACE") == "all") if usingProxy { + http.DefaultTransport = &http.Transport{ + Dial: Dial, + Proxy: http.ProxyFromEnvironment, + TLSHandshakeTimeout: 10 * time.Second, + } + // Defer this, so that logging gets setup. go func() { time.Sleep(500 * time.Millisecond) diff --git a/lib/discover/global.go b/lib/discover/global.go index f868583ef..d16acc147 100644 --- a/lib/discover/global.go +++ b/lib/discover/global.go @@ -18,6 +18,7 @@ import ( stdsync "sync" "time" + "github.com/syncthing/syncthing/lib/dialer" "github.com/syncthing/syncthing/lib/events" "github.com/syncthing/syncthing/lib/protocol" ) @@ -73,6 +74,8 @@ func NewGlobal(server string, cert tls.Certificate, addrList AddressLister, rela // certificate depending on the insecure setting. var announceClient httpClient = &http.Client{ Transport: &http.Transport{ + Dial: dialer.Dial, + Proxy: http.ProxyFromEnvironment, TLSClientConfig: &tls.Config{ InsecureSkipVerify: opts.insecure, Certificates: []tls.Certificate{cert}, @@ -87,6 +90,8 @@ func NewGlobal(server string, cert tls.Certificate, addrList AddressLister, rela // certificate here, so lets not include it. May be insecure if requested. var queryClient httpClient = &http.Client{ Transport: &http.Transport{ + Dial: dialer.Dial, + Proxy: http.ProxyFromEnvironment, TLSClientConfig: &tls.Config{ InsecureSkipVerify: opts.insecure, }, diff --git a/lib/rc/rc.go b/lib/rc/rc.go index 6e7c45a78..1b04e9048 100644 --- a/lib/rc/rc.go +++ b/lib/rc/rc.go @@ -26,6 +26,7 @@ import ( "time" "github.com/syncthing/syncthing/lib/config" + "github.com/syncthing/syncthing/lib/dialer" "github.com/syncthing/syncthing/lib/protocol" "github.com/syncthing/syncthing/lib/sync" ) @@ -156,6 +157,8 @@ func (p *Process) Get(path string) ([]byte, error) { client := &http.Client{ Timeout: 30 * time.Second, Transport: &http.Transport{ + Dial: dialer.Dial, + Proxy: http.ProxyFromEnvironment, DisableKeepAlives: true, }, } diff --git a/lib/upgrade/upgrade_supported.go b/lib/upgrade/upgrade_supported.go index c6651bb9e..4dbad86d8 100644 --- a/lib/upgrade/upgrade_supported.go +++ b/lib/upgrade/upgrade_supported.go @@ -26,6 +26,7 @@ import ( "sort" "strings" + "github.com/syncthing/syncthing/lib/dialer" "github.com/syncthing/syncthing/lib/signature" ) @@ -38,6 +39,8 @@ const DisabledByCompilation = false // binary contents before accepting the upgrade. var insecureHTTP = &http.Client{ Transport: &http.Transport{ + Dial: dialer.Dial, + Proxy: http.ProxyFromEnvironment, TLSClientConfig: &tls.Config{ InsecureSkipVerify: true, },