Skip to content

Commit

Permalink
requests: Block use of http.DefaultClient
Browse files Browse the repository at this point in the history
  • Loading branch information
earthboundkid committed Aug 9, 2024
1 parent 6eb4476 commit 5957031
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 4 additions & 1 deletion pkg/almanack/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/spotlightpa/almanack/internal/index"
"github.com/spotlightpa/almanack/internal/mailchimp"
"github.com/spotlightpa/almanack/internal/plausible"
"github.com/spotlightpa/almanack/pkg/almlog"
)

func AddFlags(fl *flag.FlagSet) func() (svc Services, err error) {
Expand Down Expand Up @@ -42,7 +43,9 @@ func AddFlags(fl *flag.FlagSet) func() (svc Services, err error) {
return
}

client := *http.DefaultClient
client := http.Client{
Transport: almlog.HTTPTransport,
}

is, fs := getS3Store()
mc := mailchimp.NewMailService(*mailServiceAPIKey, *mailServiceListID, &client)
Expand Down
7 changes: 6 additions & 1 deletion pkg/almlog/httplogger.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package almlog

import (
"errors"
"net/http"
"time"

"github.com/carlmjohnson/requests"
)

var HTTPTransport http.RoundTripper

func init() {
http.DefaultTransport = requests.LogTransport(http.DefaultTransport, logReq)
HTTPTransport = requests.LogTransport(http.DefaultTransport, logReq)
http.DefaultTransport = requests.ErrorTransport(errors.New("use of http.DefaultTransport"))
http.DefaultClient.Transport = requests.ErrorTransport(errors.New("use of http.DefaultClient"))
}

func logReq(req *http.Request, res *http.Response, err error, duration time.Duration) {
Expand Down

0 comments on commit 5957031

Please sign in to comment.