Skip to content

Commit dd65f9c

Browse files
committed
Add WithDialTLSContextFunc option
Signed-off-by: Levi Harrison <[email protected]>
1 parent 296ec92 commit dd65f9c

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

Diff for: config/http_config.go

+19-6
Original file line numberDiff line numberDiff line change
@@ -414,24 +414,36 @@ func (a *BasicAuth) UnmarshalYAML(unmarshal func(interface{}) error) error {
414414
// by net.Dialer.
415415
type DialContextFunc func(context.Context, string, string) (net.Conn, error)
416416

417+
// DialTLSContextFunc defines the signature of the DialContext() function implemented
418+
// by tls.Dialer.
419+
type DialTLSContextFunc func(context.Context, string, string) (net.Conn, error)
420+
417421
type httpClientOptions struct {
418-
dialContextFunc DialContextFunc
419-
keepAlivesEnabled bool
420-
http2Enabled bool
421-
idleConnTimeout time.Duration
422-
userAgent string
422+
dialContextFunc DialContextFunc
423+
dialTLSContextFunc DialTLSContextFunc
424+
keepAlivesEnabled bool
425+
http2Enabled bool
426+
idleConnTimeout time.Duration
427+
userAgent string
423428
}
424429

425430
// HTTPClientOption defines an option that can be applied to the HTTP client.
426431
type HTTPClientOption func(options *httpClientOptions)
427432

428-
// WithDialContextFunc allows you to override func gets used for the actual dialing. The default is `net.Dialer.DialContext`.
433+
// WithDialContextFunc allows you to override the func that gets used for the actual dialing. The default is `net.Dialer.DialContext`.
429434
func WithDialContextFunc(fn DialContextFunc) HTTPClientOption {
430435
return func(opts *httpClientOptions) {
431436
opts.dialContextFunc = fn
432437
}
433438
}
434439

440+
// WithDialTLSContextFunc allows you to override the func that gets used for the actual dialing. The default is `tls.Dialer.DialContext`.
441+
func WithDialTLSContextFunc(fn DialTLSContextFunc) HTTPClientOption {
442+
return func(opts *httpClientOptions) {
443+
opts.dialTLSContextFunc = fn
444+
}
445+
}
446+
435447
// WithKeepAlivesDisabled allows to disable HTTP keepalive.
436448
func WithKeepAlivesDisabled() HTTPClientOption {
437449
return func(opts *httpClientOptions) {
@@ -519,6 +531,7 @@ func NewRoundTripperFromConfig(cfg HTTPClientConfig, name string, optFuncs ...HT
519531
TLSHandshakeTimeout: 10 * time.Second,
520532
ExpectContinueTimeout: 1 * time.Second,
521533
DialContext: dialContext,
534+
DialTLSContext: opts.dialTLSContextFunc,
522535
}
523536
if opts.http2Enabled && cfg.EnableHTTP2 {
524537
// HTTP/2 support is golang had many problematic cornercases where

0 commit comments

Comments
 (0)