Skip to content

Commit

Permalink
Fix Echo.Serve() will no serve on HTTP port correctly when there is a…
Browse files Browse the repository at this point in the history
…lready TLSListener set to Echo instance. (labstack#1785)

This is problem when user tries to use HTTP (e.Listener) and HTTPS (e.TLSListener) with same Echo instance.
  • Loading branch information
aldas committed Feb 27, 2021
1 parent d9e2354 commit 85a711c
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ func (e *Echo) Start(address string) error {
return err
}
e.startupMutex.Unlock()
return e.serve()
return e.Server.Serve(e.Listener)
}

// StartTLS starts an HTTPS server.
Expand Down Expand Up @@ -740,8 +740,12 @@ func (e *Echo) StartServer(s *http.Server) (err error) {
e.startupMutex.Unlock()
return err
}
if s.TLSConfig != nil {
e.startupMutex.Unlock()
return s.Serve(e.TLSListener)
}
e.startupMutex.Unlock()
return e.serve()
return s.Serve(e.Listener)
}

func (e *Echo) configureServer(s *http.Server) (err error) {
Expand Down Expand Up @@ -782,13 +786,6 @@ func (e *Echo) configureServer(s *http.Server) (err error) {
return nil
}

func (e *Echo) serve() error {
if e.TLSListener != nil {
return e.Server.Serve(e.TLSListener)
}
return e.Server.Serve(e.Listener)
}

// ListenerAddr returns net.Addr for Listener
func (e *Echo) ListenerAddr() net.Addr {
e.startupMutex.RLock()
Expand Down

0 comments on commit 85a711c

Please sign in to comment.