Browse Source

graceful: import cloneTLSConfig from net/http

Carl Jackson 10 years ago
parent
commit
a01dd37b8f
3 changed files with 46 additions and 1 deletions
  1. +11
    -0
      graceful/clone.go
  2. +34
    -0
      graceful/clone16.go
  3. +1
    -1
      graceful/server.go

+ 11
- 0
graceful/clone.go View File

@ -0,0 +1,11 @@
// +build !go1.6
package graceful
import "crypto/tls"
// see clone16.go
func cloneTLSConfig(cfg *tls.Config) *tls.Config {
c := *cfg
return &c
}

+ 34
- 0
graceful/clone16.go View File

@ -0,0 +1,34 @@
// +build go1.6
package graceful
import "crypto/tls"
// cloneTLSConfig was taken from the Go standard library's net/http package. We
// need it because tls.Config objects now contain a sync.Once.
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,
SessionTicketsDisabled: cfg.SessionTicketsDisabled,
SessionTicketKey: cfg.SessionTicketKey,
ClientSessionCache: cfg.ClientSessionCache,
MinVersion: cfg.MinVersion,
MaxVersion: cfg.MaxVersion,
CurvePreferences: cfg.CurvePreferences,
}
}

+ 1
- 1
graceful/server.go View File

@ -58,7 +58,7 @@ func (srv *Server) ListenAndServeTLS(certFile, keyFile string) error {
MinVersion: tls.VersionTLS10,
}
if srv.TLSConfig != nil {
*config = *srv.TLSConfig
config = cloneTLSConfig(srv.TLSConfig)
}
if config.NextProtos == nil {
config.NextProtos = []string{"http/1.1"}


Loading…
Cancel
Save