Skip to content

Commit

Permalink
Update cloneTLSConfig to use Go 1.8 Config.Clone method
Browse files Browse the repository at this point in the history
  • Loading branch information
wstrm authored and garyburd committed Feb 18, 2017
1 parent 9acaa68 commit 3f3e394
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 29 deletions.
29 changes: 0 additions & 29 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,32 +389,3 @@ func (d *Dialer) Dial(urlStr string, requestHeader http.Header) (*Conn, *http.Re
netConn = nil // to avoid close in defer.
return conn, resp, nil
}

// cloneTLSConfig clones all public fields except the fields
// SessionTicketsDisabled and SessionTicketKey. This avoids copying the
// sync.Mutex in the sync.Once and makes it safe to call cloneTLSConfig on a
// config in active use.
func cloneTLSConfig(cfg *tls.Config) *tls.Config {
if cfg == nil {
return &tls.Config{}
}
return &tls.Config{
Rand: cfg.Rand,
Time: cfg.Time,
Certificates: cfg.Certificates,
NameToCertificate: cfg.NameToCertificate,
GetCertificate: cfg.GetCertificate,
RootCAs: cfg.RootCAs,
NextProtos: cfg.NextProtos,
ServerName: cfg.ServerName,
ClientAuth: cfg.ClientAuth,
ClientCAs: cfg.ClientCAs,
InsecureSkipVerify: cfg.InsecureSkipVerify,
CipherSuites: cfg.CipherSuites,
PreferServerCipherSuites: cfg.PreferServerCipherSuites,
ClientSessionCache: cfg.ClientSessionCache,
MinVersion: cfg.MinVersion,
MaxVersion: cfg.MaxVersion,
CurvePreferences: cfg.CurvePreferences,
}
}
16 changes: 16 additions & 0 deletions client_clone.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2013 The Gorilla WebSocket Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build go1.8

package websocket

import "crypto/tls"

func cloneTLSConfig(cfg *tls.Config) *tls.Config {
if cfg == nil {
return &tls.Config{}
}
return cfg.Clone()

This comment has been minimized.

Copy link
@hyhlinux

hyhlinux Mar 21, 2017

vendor/github.com/gorilla/websocket/client_clone.go:15: cfg.Clone undefined (type *tls.Config has no field or method Clone, but does have tls.clone)
why i get this?

This comment has been minimized.

Copy link
@hyhlinux

hyhlinux Mar 21, 2017

➜ minicdn git:(hyh) ✗ go version
go version go1.8 darwin/amd64
➜ minicdn git:(hyh) ✗

This comment has been minimized.

Copy link
@garyburd

garyburd Mar 21, 2017

Contributor

The Clone method is in Go 1.8. You get this error because the standard library files in your Go installation do not match the version of the tools.

}
38 changes: 38 additions & 0 deletions client_clone_legacy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2013 The Gorilla WebSocket Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build !go1.8

package websocket

import "crypto/tls"

// cloneTLSConfig clones all public fields except the fields
// SessionTicketsDisabled and SessionTicketKey. This avoids copying the
// sync.Mutex in the sync.Once and makes it safe to call cloneTLSConfig on a
// config in active use.
func cloneTLSConfig(cfg *tls.Config) *tls.Config {
if cfg == nil {
return &tls.Config{}
}
return &tls.Config{
Rand: cfg.Rand,
Time: cfg.Time,
Certificates: cfg.Certificates,
NameToCertificate: cfg.NameToCertificate,
GetCertificate: cfg.GetCertificate,
RootCAs: cfg.RootCAs,
NextProtos: cfg.NextProtos,
ServerName: cfg.ServerName,
ClientAuth: cfg.ClientAuth,
ClientCAs: cfg.ClientCAs,
InsecureSkipVerify: cfg.InsecureSkipVerify,
CipherSuites: cfg.CipherSuites,
PreferServerCipherSuites: cfg.PreferServerCipherSuites,
ClientSessionCache: cfg.ClientSessionCache,
MinVersion: cfg.MinVersion,
MaxVersion: cfg.MaxVersion,
CurvePreferences: cfg.CurvePreferences,
}
}

0 comments on commit 3f3e394

Please sign in to comment.