Skip to content

Commit

Permalink
A bit cleaner setting of http client
Browse files Browse the repository at this point in the history
  • Loading branch information
myleshorton committed Dec 9, 2024
1 parent 06fe985 commit 0b2d613
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 22 deletions.
18 changes: 2 additions & 16 deletions email/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"encoding/hex"
"fmt"
"math"
"net/http"
"strconv"
"strings"
"sync"
Expand All @@ -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"
)

Expand All @@ -37,7 +37,6 @@ var (
// Limit text logtail to 1MB
maxLogTailSize = 1024768
defaultRecipient string
httpClient = &http.Client{}
mu sync.RWMutex
)

Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 0 additions & 4 deletions email/email_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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: "[email protected]",
Expand Down
2 changes: 0 additions & 2 deletions flashlight.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 0b2d613

Please sign in to comment.