Skip to content

Commit 85a711c

Browse files
committed
Fix Echo.Serve() will no serve on HTTP port correctly when there is already TLSListener set to Echo instance. (#1785)
This is problem when user tries to use HTTP (e.Listener) and HTTPS (e.TLSListener) with same Echo instance.
1 parent d9e2354 commit 85a711c

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

echo.go

+6-9
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ func (e *Echo) Start(address string) error {
660660
return err
661661
}
662662
e.startupMutex.Unlock()
663-
return e.serve()
663+
return e.Server.Serve(e.Listener)
664664
}
665665

666666
// StartTLS starts an HTTPS server.
@@ -740,8 +740,12 @@ func (e *Echo) StartServer(s *http.Server) (err error) {
740740
e.startupMutex.Unlock()
741741
return err
742742
}
743+
if s.TLSConfig != nil {
744+
e.startupMutex.Unlock()
745+
return s.Serve(e.TLSListener)
746+
}
743747
e.startupMutex.Unlock()
744-
return e.serve()
748+
return s.Serve(e.Listener)
745749
}
746750

747751
func (e *Echo) configureServer(s *http.Server) (err error) {
@@ -782,13 +786,6 @@ func (e *Echo) configureServer(s *http.Server) (err error) {
782786
return nil
783787
}
784788

785-
func (e *Echo) serve() error {
786-
if e.TLSListener != nil {
787-
return e.Server.Serve(e.TLSListener)
788-
}
789-
return e.Server.Serve(e.Listener)
790-
}
791-
792789
// ListenerAddr returns net.Addr for Listener
793790
func (e *Echo) ListenerAddr() net.Addr {
794791
e.startupMutex.RLock()

0 commit comments

Comments
 (0)