Skip to content

Commit 6eb2249

Browse files
zxpdmwerikdubbelboer
andauthoredJul 18, 2023
fix:fasthttp server with tlsConfig (#1595)
* fix:fasthttp server with tlsConfig Signed-off-by: zhangweiyu <zhangweiyu2@huawei.com> * fix:fasthttp server with tlsConfig Signed-off-by: zhangweiyu <zhangweiyu2@huawei.com> * Update server.go Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com> * fix:fasthttp server with tlsConfig Signed-off-by: zhangweiyu <zhangweiyu2@huawei.com> * fix:fasthttp server with tlsConfig Signed-off-by: zhangweiyu <zhangweiyu2@huawei.com> --------- Signed-off-by: zhangweiyu <zhangweiyu2@huawei.com> Co-authored-by: zhangweiyu <zhangweiyu2@huawei.com> Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
1 parent 1c85d43 commit 6eb2249

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed
 

‎server.go

+14-17
Original file line numberDiff line numberDiff line change
@@ -1677,14 +1677,13 @@ func (s *Server) ListenAndServeTLSEmbed(addr string, certData, keyData []byte) e
16771677
// the function will use previously added TLS configuration.
16781678
func (s *Server) ServeTLS(ln net.Listener, certFile, keyFile string) error {
16791679
s.mu.Lock()
1680-
err := s.AppendCert(certFile, keyFile)
1681-
if err != nil && err != errNoCertOrKeyProvided {
1682-
s.mu.Unlock()
1683-
return err
1684-
}
1685-
if s.TLSConfig == nil {
1686-
s.mu.Unlock()
1687-
return errNoCertOrKeyProvided
1680+
s.configTLS()
1681+
configHasCert := len(s.TLSConfig.Certificates) > 0 || s.TLSConfig.GetCertificate != nil
1682+
if !configHasCert || certFile != "" || keyFile != "" {
1683+
if err := s.AppendCert(certFile, keyFile); err != nil {
1684+
s.mu.Unlock()
1685+
return err
1686+
}
16881687
}
16891688

16901689
// BuildNameToCertificate has been deprecated since 1.14.
@@ -1706,15 +1705,13 @@ func (s *Server) ServeTLS(ln net.Listener, certFile, keyFile string) error {
17061705
// the function will use previously added TLS configuration.
17071706
func (s *Server) ServeTLSEmbed(ln net.Listener, certData, keyData []byte) error {
17081707
s.mu.Lock()
1709-
1710-
err := s.AppendCertEmbed(certData, keyData)
1711-
if err != nil && err != errNoCertOrKeyProvided {
1712-
s.mu.Unlock()
1713-
return err
1714-
}
1715-
if s.TLSConfig == nil {
1716-
s.mu.Unlock()
1717-
return errNoCertOrKeyProvided
1708+
s.configTLS()
1709+
configHasCert := len(s.TLSConfig.Certificates) > 0 || s.TLSConfig.GetCertificate != nil
1710+
if !configHasCert || len(certData) != 0 || len(keyData) != 0 {
1711+
if err := s.AppendCertEmbed(certData, keyData); err != nil {
1712+
s.mu.Unlock()
1713+
return err
1714+
}
17181715
}
17191716

17201717
// BuildNameToCertificate has been deprecated since 1.14.

0 commit comments

Comments
 (0)
Please sign in to comment.