]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Add ClientConfig.WebTransport
authorMatt Joiner <anacrolix@gmail.com>
Tue, 22 Aug 2023 02:44:49 +0000 (12:44 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Tue, 22 Aug 2023 02:53:54 +0000 (12:53 +1000)
client.go
config.go

index f1a054abc6708a223e3c4159de7e53cb0c35ce84..1ea1d610482551bfef1d621f0ba03bd5cf6f3667 100644 (file)
--- 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,
-               },
+               }
        }
 }
 
index cfcfe392c3beb0d550c9ff6b6b451cb2f4eb2019..0c029a7e2c3e4ba0b2bf98008ebaaad1e9225fb0 100644 (file)
--- 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)