Skip to content

Commit

Permalink
fix:fasthttp server with tlsConfig (#1595)
Browse files Browse the repository at this point in the history
* fix:fasthttp server with tlsConfig

Signed-off-by: zhangweiyu <[email protected]>

* fix:fasthttp server with tlsConfig

Signed-off-by: zhangweiyu <[email protected]>

* Update server.go

Co-authored-by: Erik Dubbelboer <[email protected]>

* fix:fasthttp server with tlsConfig

Signed-off-by: zhangweiyu <[email protected]>

* fix:fasthttp server with tlsConfig

Signed-off-by: zhangweiyu <[email protected]>

---------

Signed-off-by: zhangweiyu <[email protected]>
Co-authored-by: zhangweiyu <[email protected]>
Co-authored-by: Erik Dubbelboer <[email protected]>
  • Loading branch information
3 people authored Jul 18, 2023
1 parent 1c85d43 commit 6eb2249
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1677,14 +1677,13 @@ func (s *Server) ListenAndServeTLSEmbed(addr string, certData, keyData []byte) e
// the function will use previously added TLS configuration.
func (s *Server) ServeTLS(ln net.Listener, certFile, keyFile string) error {
s.mu.Lock()
err := s.AppendCert(certFile, keyFile)
if err != nil && err != errNoCertOrKeyProvided {
s.mu.Unlock()
return err
}
if s.TLSConfig == nil {
s.mu.Unlock()
return errNoCertOrKeyProvided
s.configTLS()
configHasCert := len(s.TLSConfig.Certificates) > 0 || s.TLSConfig.GetCertificate != nil
if !configHasCert || certFile != "" || keyFile != "" {
if err := s.AppendCert(certFile, keyFile); err != nil {
s.mu.Unlock()
return err
}
}

// BuildNameToCertificate has been deprecated since 1.14.
Expand All @@ -1706,15 +1705,13 @@ func (s *Server) ServeTLS(ln net.Listener, certFile, keyFile string) error {
// the function will use previously added TLS configuration.
func (s *Server) ServeTLSEmbed(ln net.Listener, certData, keyData []byte) error {
s.mu.Lock()

err := s.AppendCertEmbed(certData, keyData)
if err != nil && err != errNoCertOrKeyProvided {
s.mu.Unlock()
return err
}
if s.TLSConfig == nil {
s.mu.Unlock()
return errNoCertOrKeyProvided
s.configTLS()
configHasCert := len(s.TLSConfig.Certificates) > 0 || s.TLSConfig.GetCertificate != nil
if !configHasCert || len(certData) != 0 || len(keyData) != 0 {
if err := s.AppendCertEmbed(certData, keyData); err != nil {
s.mu.Unlock()
return err
}
}

// BuildNameToCertificate has been deprecated since 1.14.
Expand Down

0 comments on commit 6eb2249

Please sign in to comment.