diff options
author | Zhang Xiaopei <51427547+zxpdmw@users.noreply.github.com> | 2023-07-18 19:00:15 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-18 13:00:15 +0200 |
commit | 6eb224954a5b6538ff23fc0371c0454e60c78670 (patch) | |
tree | 998255aa1878be2d65b58615864bb750867daa7a /server.go | |
parent | Fix round2 (diff) | |
download | fasthttp-6eb224954a5b6538ff23fc0371c0454e60c78670.tar.gz fasthttp-6eb224954a5b6538ff23fc0371c0454e60c78670.tar.bz2 fasthttp-6eb224954a5b6538ff23fc0371c0454e60c78670.zip |
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>
Diffstat (limited to 'server.go')
-rw-r--r-- | server.go | 31 |
1 files changed, 14 insertions, 17 deletions
@@ -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. @@ -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. |