From d3a0805a2b422f74f5899908a6f644803429d7a1 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Tue, 19 Aug 2025 17:13:48 +0100 Subject: [PATCH] fshttp: return *Transport rather than http.RoundTripper from NewTransport This allows further customization, reading the existing config and is the Go recommended way "accept interfaces, return structs". --- fs/fshttp/http.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/fshttp/http.go b/fs/fshttp/http.go index bcf79f94c..de9ca3cf8 100644 --- a/fs/fshttp/http.go +++ b/fs/fshttp/http.go @@ -28,7 +28,7 @@ const ( ) var ( - transport http.RoundTripper + transport *Transport noTransport = new(sync.Once) cookieJar, _ = cookiejar.New(&cookiejar.Options{PublicSuffixList: publicsuffix.List}) logMutex sync.Mutex @@ -51,7 +51,7 @@ func ResetTransport() { // NewTransportCustom returns an http.RoundTripper with the correct timeouts. // The customize function is called if set to give the caller an opportunity to // customize any defaults in the Transport. -func NewTransportCustom(ctx context.Context, customize func(*http.Transport)) http.RoundTripper { +func NewTransportCustom(ctx context.Context, customize func(*http.Transport)) *Transport { ci := fs.GetConfig(ctx) // Start with a sensible set of defaults then override. // This also means we get new stuff when it gets added to go @@ -145,7 +145,7 @@ func NewTransportCustom(ctx context.Context, customize func(*http.Transport)) ht } // NewTransport returns an http.RoundTripper with the correct timeouts -func NewTransport(ctx context.Context) http.RoundTripper { +func NewTransport(ctx context.Context) *Transport { (*noTransport).Do(func() { transport = NewTransportCustom(ctx, nil) })