From: Raphaël Thériault Date: Mon, 14 Nov 2022 08:19:02 +0000 (-0800) Subject: support providing a DialContext for the http client (#786) X-Git-Tag: v1.48.0~21 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=8e53dbaeb8abc26fb6edc52b85f1dd7beffeb07f;p=btrtrc.git support providing a DialContext for the http client (#786) --- diff --git a/client.go b/client.go index e0aea952..a77aea84 100644 --- a/client.go +++ b/client.go @@ -203,7 +203,8 @@ func (cl *Client) init(cfg *ClientConfig) { cl.ipBlockList = cfg.IPBlocklist cl.httpClient = &http.Client{ Transport: &http.Transport{ - Proxy: cfg.HTTPProxy, + 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 11e70d68..1189872e 100644 --- a/config.go +++ b/config.go @@ -91,6 +91,8 @@ type ClientConfig struct { // 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) + // Defines DialContext func to use for HTTP requests, such as for fetching metainfo and webtorrent seeds + HTTPDialContext func(ctx context.Context, network, addr string) (net.Conn, error) // Defines DialContext func to use for HTTP tracker announcements TrackerDialContext func(ctx context.Context, network, addr string) (net.Conn, error) // Defines ListenPacket func to use for UDP tracker announcements