client: add a WithNoProxy dialoption (#3411)
This commit is contained in:
Родитель
5dbd4c232c
Коммит
e965f2a60b
|
@ -194,12 +194,13 @@ func DialContext(ctx context.Context, target string, opts ...DialOption) (conn *
|
||||||
cc.mkp = cc.dopts.copts.KeepaliveParams
|
cc.mkp = cc.dopts.copts.KeepaliveParams
|
||||||
|
|
||||||
if cc.dopts.copts.Dialer == nil {
|
if cc.dopts.copts.Dialer == nil {
|
||||||
cc.dopts.copts.Dialer = newProxyDialer(
|
cc.dopts.copts.Dialer = func(ctx context.Context, addr string) (net.Conn, error) {
|
||||||
func(ctx context.Context, addr string) (net.Conn, error) {
|
network, addr := parseDialTarget(addr)
|
||||||
network, addr := parseDialTarget(addr)
|
return (&net.Dialer{}).DialContext(ctx, network, addr)
|
||||||
return (&net.Dialer{}).DialContext(ctx, network, addr)
|
}
|
||||||
},
|
if cc.dopts.withProxy {
|
||||||
)
|
cc.dopts.copts.Dialer = newProxyDialer(cc.dopts.copts.Dialer)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if cc.dopts.copts.UserAgent != "" {
|
if cc.dopts.copts.UserAgent != "" {
|
||||||
|
|
|
@ -72,6 +72,7 @@ type dialOptions struct {
|
||||||
// we need to be able to configure this in tests.
|
// we need to be able to configure this in tests.
|
||||||
resolveNowBackoff func(int) time.Duration
|
resolveNowBackoff func(int) time.Duration
|
||||||
resolvers []resolver.Builder
|
resolvers []resolver.Builder
|
||||||
|
withProxy bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// DialOption configures how we set up the connection.
|
// DialOption configures how we set up the connection.
|
||||||
|
@ -307,6 +308,16 @@ func WithInsecure() DialOption {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithNoProxy returns a DialOption which disables the use of proxies for this
|
||||||
|
// ClientConn. This is ignored if WithDialer or WithContextDialer are used.
|
||||||
|
//
|
||||||
|
// This API is EXPERIMENTAL.
|
||||||
|
func WithNoProxy() DialOption {
|
||||||
|
return newFuncDialOption(func(o *dialOptions) {
|
||||||
|
o.withProxy = false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// WithTransportCredentials returns a DialOption which configures a connection
|
// WithTransportCredentials returns a DialOption which configures a connection
|
||||||
// level security credentials (e.g., TLS/SSL). This should not be used together
|
// level security credentials (e.g., TLS/SSL). This should not be used together
|
||||||
// with WithCredentialsBundle.
|
// with WithCredentialsBundle.
|
||||||
|
@ -557,6 +568,7 @@ func defaultDialOptions() dialOptions {
|
||||||
ReadBufferSize: defaultReadBufSize,
|
ReadBufferSize: defaultReadBufSize,
|
||||||
},
|
},
|
||||||
resolveNowBackoff: internalbackoff.DefaultExponential.Backoff,
|
resolveNowBackoff: internalbackoff.DefaultExponential.Backoff,
|
||||||
|
withProxy: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче