From 17279ac7e1f4c899d4c2488eff351ab689847208 Mon Sep 17 00:00:00 2001 From: Patrick Bogen Date: Fri, 28 Feb 2020 15:51:29 -0800 Subject: [PATCH 1/3] add a WithoutProxy dialoption --- clientconn.go | 13 +++++++------ dialoptions.go | 9 +++++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/clientconn.go b/clientconn.go index 293d2f62fd1e..7c4cb07ecaad 100644 --- a/clientconn.go +++ b/clientconn.go @@ -194,12 +194,13 @@ func DialContext(ctx context.Context, target string, opts ...DialOption) (conn * cc.mkp = cc.dopts.copts.KeepaliveParams if cc.dopts.copts.Dialer == nil { - cc.dopts.copts.Dialer = newProxyDialer( - func(ctx context.Context, addr string) (net.Conn, error) { - network, addr := parseDialTarget(addr) - return (&net.Dialer{}).DialContext(ctx, network, addr) - }, - ) + cc.dopts.copts.Dialer = func(ctx context.Context, addr string) (net.Conn, error) { + network, addr := parseDialTarget(addr) + return (&net.Dialer{}).DialContext(ctx, network, addr) + } + if !cc.dopts.withoutProxy { + cc.dopts.copts.Dialer = newProxyDialer(cc.dopts.copts.Dialer) + } } if cc.dopts.copts.UserAgent != "" { diff --git a/dialoptions.go b/dialoptions.go index 63f5ae21df1d..d45b9df67dee 100644 --- a/dialoptions.go +++ b/dialoptions.go @@ -72,6 +72,7 @@ type dialOptions struct { // we need to be able to configure this in tests. resolveNowBackoff func(int) time.Duration resolvers []resolver.Builder + withoutProxy bool } // DialOption configures how we set up the connection. @@ -307,6 +308,14 @@ func WithInsecure() DialOption { }) } +// WithoutProxy returns a DialOption which disables the use of proxies for this +// ClientConn. This is ignored if WithDialer or WithContextDialer are used. +func WithoutProxy() DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.withoutProxy = true + }) +} + // WithTransportCredentials returns a DialOption which configures a connection // level security credentials (e.g., TLS/SSL). This should not be used together // with WithCredentialsBundle. From ba34f11409f094241bcfa554fbe8106e81774835 Mon Sep 17 00:00:00 2001 From: Patrick Bogen Date: Thu, 26 Mar 2020 14:14:07 -0700 Subject: [PATCH 2/3] rename WithoutProxy -> WithNoProxy --- dialoptions.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/dialoptions.go b/dialoptions.go index d45b9df67dee..e9953f5eca23 100644 --- a/dialoptions.go +++ b/dialoptions.go @@ -308,9 +308,11 @@ func WithInsecure() DialOption { }) } -// WithoutProxy returns a DialOption which disables the use of proxies for this +// WithNoProxy returns a DialOption which disables the use of proxies for this // ClientConn. This is ignored if WithDialer or WithContextDialer are used. -func WithoutProxy() DialOption { +// +// This API is EXPERIMENTAL. +func WithNoProxy() DialOption { return newFuncDialOption(func(o *dialOptions) { o.withoutProxy = true }) From 719458203cc124a4f6de07508f9a07572b48dd17 Mon Sep 17 00:00:00 2001 From: Patrick Bogen Date: Thu, 26 Mar 2020 14:14:14 -0700 Subject: [PATCH 3/3] invert flag withoutProxy -> withProxy --- clientconn.go | 2 +- dialoptions.go | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/clientconn.go b/clientconn.go index 7c4cb07ecaad..5b48e4c7aafa 100644 --- a/clientconn.go +++ b/clientconn.go @@ -198,7 +198,7 @@ func DialContext(ctx context.Context, target string, opts ...DialOption) (conn * network, addr := parseDialTarget(addr) return (&net.Dialer{}).DialContext(ctx, network, addr) } - if !cc.dopts.withoutProxy { + if cc.dopts.withProxy { cc.dopts.copts.Dialer = newProxyDialer(cc.dopts.copts.Dialer) } } diff --git a/dialoptions.go b/dialoptions.go index e9953f5eca23..35bde1033a7f 100644 --- a/dialoptions.go +++ b/dialoptions.go @@ -72,7 +72,7 @@ type dialOptions struct { // we need to be able to configure this in tests. resolveNowBackoff func(int) time.Duration resolvers []resolver.Builder - withoutProxy bool + withProxy bool } // DialOption configures how we set up the connection. @@ -314,7 +314,7 @@ func WithInsecure() DialOption { // This API is EXPERIMENTAL. func WithNoProxy() DialOption { return newFuncDialOption(func(o *dialOptions) { - o.withoutProxy = true + o.withProxy = false }) } @@ -568,6 +568,7 @@ func defaultDialOptions() dialOptions { ReadBufferSize: defaultReadBufSize, }, resolveNowBackoff: internalbackoff.DefaultExponential.Backoff, + withProxy: true, } }