From 4bb8f8f836b13f3800368828b7b746b2438ce543 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Tue, 22 Aug 2023 12:44:49 +1000 Subject: [PATCH] Add ClientConfig.WebTransport --- client.go | 7 +++++-- config.go | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/client.go b/client.go index f1a054ab..1ea1d610 100644 --- a/client.go +++ b/client.go @@ -203,13 +203,16 @@ func (cl *Client) init(cfg *ClientConfig) { cl.event.L = cl.locker() cl.ipBlockList = cfg.IPBlocklist cl.httpClient = &http.Client{ - Transport: &http.Transport{ + Transport: cfg.WebTransport, + } + if cl.httpClient.Transport == nil { + cl.httpClient.Transport = &http.Transport{ Proxy: cfg.HTTPProxy, DialContext: cfg.HTTPDialContext, // I think this value was observed from some webseeds. It seems reasonable to extend it // to other uses of HTTP from the client. MaxConnsPerHost: 10, - }, + } } } diff --git a/config.go b/config.go index cfcfe392..0c029a7e 100644 --- a/config.go +++ b/config.go @@ -107,6 +107,8 @@ type ClientConfig struct { Debug bool `help:"enable debugging"` Logger log.Logger + // Used for torrent sources and webseeding if set. + WebTransport http.RoundTripper // Defines proxy for HTTP requests, such as for trackers. It's commonly set from the result of // "net/http".ProxyURL(HTTPProxy). HTTPProxy func(*http.Request) (*url.URL, error) -- 2.44.0