Skip to content

Commit 5ada9b5

Browse files
committed
TLS support
Signed-off-by: Vishal Rana <[email protected]>
1 parent fb04f99 commit 5ada9b5

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

engine/engine.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ type (
6262

6363
Config struct {
6464
Address string
65-
ReadTimeout time.Duration
66-
WriteTimeout time.Duration
6765
TLSCertfile string
6866
TLSKeyfile string
67+
ReadTimeout time.Duration
68+
WriteTimeout time.Duration
6969
}
7070
)

engine/fasthttp/server.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
package fasthttp
44

55
import (
6-
"net/http"
76
"sync"
87

98
"github.com/labstack/echo/engine"
@@ -14,7 +13,6 @@ import (
1413

1514
type (
1615
Server struct {
17-
*http.Server
1816
config *engine.Config
1917
handler engine.HandlerFunc
2018
pool *Pool
@@ -46,7 +44,6 @@ func NewTLS(addr, certfile, keyfile string) *Server {
4644

4745
func NewConfig(c *engine.Config) (s *Server) {
4846
s = &Server{
49-
Server: new(http.Server),
5047
config: c,
5148
pool: &Pool{
5249
request: sync.Pool{
@@ -92,7 +89,7 @@ func (s *Server) SetLogger(l logger.Logger) {
9289
}
9390

9491
func (s *Server) Start() {
95-
fasthttp.ListenAndServe(s.config.Address, func(c *fasthttp.RequestCtx) {
92+
handler := func(c *fasthttp.RequestCtx) {
9693
// Request
9794
req := s.pool.request.Get().(*Request)
9895
reqHdr := s.pool.requestHeader.Get().(*RequestHeader)
@@ -114,6 +111,14 @@ func (s *Server) Start() {
114111
s.pool.url.Put(reqURL)
115112
s.pool.response.Put(res)
116113
s.pool.responseHeader.Put(resHdr)
117-
})
118-
s.logger.Fatal(s.ListenAndServe())
114+
}
115+
116+
addr := s.config.Address
117+
certfile := s.config.TLSCertfile
118+
keyfile := s.config.TLSKeyfile
119+
if certfile != "" && keyfile != "" {
120+
s.logger.Fatal(fasthttp.ListenAndServeTLS(addr, certfile, keyfile, handler))
121+
} else {
122+
s.logger.Fatal(fasthttp.ListenAndServe(addr, handler))
123+
}
119124
}

engine/standard/server.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,5 +107,12 @@ func (s *Server) Start() {
107107
s.pool.response.Put(res)
108108
s.pool.header.Put(resHdr)
109109
})
110-
s.logger.Fatal(s.ListenAndServe())
110+
111+
certfile := s.config.TLSCertfile
112+
keyfile := s.config.TLSKeyfile
113+
if certfile != "" && keyfile != "" {
114+
s.logger.Fatal(s.ListenAndServeTLS(certfile, keyfile))
115+
} else {
116+
s.logger.Fatal(s.ListenAndServe())
117+
}
111118
}

0 commit comments

Comments
 (0)