From b2adf54f3ca98a1af3a33223092a250bd5002ae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Thu, 26 Jul 2018 18:53:11 +0300 Subject: [PATCH] client/v2: support custom dialer, not just socks proxy --- client/v2/client.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/client/v2/client.go b/client/v2/client.go index 6a5c238bcd..612937201b 100644 --- a/client/v2/client.go +++ b/client/v2/client.go @@ -3,6 +3,7 @@ package client // import "github.com/influxdata/influxdb/client/v2" import ( "bytes" + "context" "crypto/tls" "encoding/json" "errors" @@ -10,6 +11,7 @@ import ( "io" "io/ioutil" "mime" + "net" "net/http" "net/url" "path" @@ -48,6 +50,10 @@ type HTTPConfig struct { // Proxy configures the Proxy function on the HTTP client. Proxy func(req *http.Request) (*url.URL, error) + + // DialContext specifies the dial function for creating unencrypted TCP connections. + // If DialContext is nil then the transport dials using package net. + DialContext func(ctx context.Context, network, addr string) (net.Conn, error) } // BatchPointsConfig is the config data needed to create an instance of the BatchPoints struct. @@ -102,7 +108,8 @@ func NewHTTPClient(conf HTTPConfig) (Client, error) { TLSClientConfig: &tls.Config{ InsecureSkipVerify: conf.InsecureSkipVerify, }, - Proxy: conf.Proxy, + Proxy: conf.Proxy, + DialContext: conf.DialContext, } if conf.TLSConfig != nil { tr.TLSClientConfig = conf.TLSConfig