From 0b2d613e98e3de88f24e3535d39e4b2e79046134 Mon Sep 17 00:00:00 2001 From: Adam Fisk Date: Mon, 9 Dec 2024 14:08:27 -0700 Subject: [PATCH] A bit cleaner setting of http client --- email/email.go | 18 ++---------------- email/email_test.go | 4 ---- flashlight.go | 2 -- 3 files changed, 2 insertions(+), 22 deletions(-) diff --git a/email/email.go b/email/email.go index 6bcf56838..30129ce39 100644 --- a/email/email.go +++ b/email/email.go @@ -8,7 +8,6 @@ import ( "encoding/hex" "fmt" "math" - "net/http" "strconv" "strings" "sync" @@ -24,6 +23,7 @@ import ( "github.com/getlantern/flashlight/v7/geolookup" "github.com/getlantern/flashlight/v7/logging" "github.com/getlantern/flashlight/v7/ops" + "github.com/getlantern/flashlight/v7/proxied" "github.com/getlantern/flashlight/v7/util" ) @@ -37,7 +37,6 @@ var ( // Limit text logtail to 1MB maxLogTailSize = 1024768 defaultRecipient string - httpClient = &http.Client{} mu sync.RWMutex ) @@ -64,19 +63,6 @@ func getDefaultRecipient() string { return defaultRecipient } -// SetHTTPClient configures an alternate http.Client to use when sending emails -func SetHTTPClient(client *http.Client) { - mu.Lock() - defer mu.Unlock() - httpClient = client -} - -func getHTTPClient() *http.Client { - mu.RLock() - defer mu.RUnlock() - return httpClient -} - // Message is a templatized email message type Message struct { // The mandrill template slug @@ -141,7 +127,7 @@ func Send(ctx context.Context, msg *Message) error { func sendTemplate(ctx context.Context, msg *Message) error { client := mandrill.ClientWithKey(Key) - client.HTTPClient = getHTTPClient() + client.HTTPClient = proxied.DirectThenFrontedClient(1 * time.Minute) recipient := msg.To if recipient == "" { recipient = getDefaultRecipient() diff --git a/email/email_test.go b/email/email_test.go index 7ee3f6911..934e0aeac 100644 --- a/email/email_test.go +++ b/email/email_test.go @@ -3,11 +3,9 @@ package email import ( "context" "io/ioutil" - "net/http" "os" "path/filepath" "testing" - "time" "github.com/keighl/mandrill" tls "github.com/refraction-networking/utls" @@ -62,8 +60,6 @@ func TestSubmitIssue(t *testing.T) { // example by setting its address to 0.0.0.0 in /etc/hosts. if false { proxied.SetFronted(newFronted()) - SetHTTPClient(proxied.DirectThenFrontedClient(5 * time.Second)) - defer SetHTTPClient(&http.Client{}) msg := &Message{ To: "ox+unittest@getlantern.org", diff --git a/flashlight.go b/flashlight.go index 82615431d..b56ebcb88 100644 --- a/flashlight.go +++ b/flashlight.go @@ -26,7 +26,6 @@ import ( userconfig "github.com/getlantern/flashlight/v7/config/user" "github.com/getlantern/flashlight/v7/dialer" "github.com/getlantern/flashlight/v7/domainrouting" - "github.com/getlantern/flashlight/v7/email" "github.com/getlantern/flashlight/v7/geolookup" "github.com/getlantern/flashlight/v7/goroutines" fops "github.com/getlantern/flashlight/v7/ops" @@ -621,7 +620,6 @@ func (f *Flashlight) RunClientListeners(httpProxyAddr, socksProxyAddr string, err := f.client.ListenAndServeHTTP(httpProxyAddr, func() { log.Debug("Started client HTTP proxy") proxied.SetProxyAddr(f.client.Addr) - email.SetHTTPClient(proxied.DirectThenFrontedClient(1 * time.Minute)) if afterStart != nil { afterStart(f.client)