Skip to content

Commit

Permalink
This adds an option to skip the TLS connection wrapper
Browse files Browse the repository at this point in the history
This option to skip the TLS wrapper is meant to be used if a custom
dialer already handled the TLS handshake. I discussed my use case,
which is using NATS from a Wasm module running in the browser in
Slack with @derekcollison. There may be other use cases when the
custom dialer is using some kind of tunneling, for example.
  • Loading branch information
oderwat committed Nov 29, 2022
1 parent 398a1ec commit c9b2fd8
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions nats.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@ type Options struct {
// transports.
TLSConfig *tls.Config

// SkipTLSWrapper does not upgrade the connection to TLS and is
// meant to be used if the custom dialer does handle TLS itself
SkipTLSWrapper bool

// AllowReconnect enables reconnection logic to be used when we
// encounter a disconnect from the current server.
AllowReconnect bool
Expand Down Expand Up @@ -1185,6 +1189,16 @@ func SetCustomDialer(dialer CustomDialer) Option {
}
}

// SetSkipTLSWrapper is an Option to be used with the CustomDialer which
// will not wrap the connection with TLS. Use it if the CustomDialer did
// already handle TLS
func SetSkipTLSWrapper(skip bool) Option {
return func(o *Options) error {
o.SkipTLSWrapper = skip
return nil
}
}

// UseOldRequestStyle is an Option to force usage of the old Request style.
func UseOldRequestStyle() Option {
return func(o *Options) error {
Expand Down Expand Up @@ -1894,6 +1908,10 @@ func (nc *Conn) createConn() (err error) {

// makeTLSConn will wrap an existing Conn using TLS
func (nc *Conn) makeTLSConn() error {
if nc.Opts.SkipTLSWrapper {
// we do nothing when asked to skip the TLS wrapper
return nil
}
// Allow the user to configure their own tls.Config structure.
var tlsCopy *tls.Config
if nc.Opts.TLSConfig != nil {
Expand Down

0 comments on commit c9b2fd8

Please sign in to comment.