1
0
mirror of https://github.com/labstack/echo.git synced 2025-07-17 01:43:02 +02:00

TLS support

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana
2016-02-22 22:24:56 -08:00
parent fb04f9979e
commit 5ada9b5f1b
3 changed files with 21 additions and 9 deletions

View File

@ -62,9 +62,9 @@ type (
Config struct {
Address string
ReadTimeout time.Duration
WriteTimeout time.Duration
TLSCertfile string
TLSKeyfile string
ReadTimeout time.Duration
WriteTimeout time.Duration
}
)

View File

@ -3,7 +3,6 @@
package fasthttp
import (
"net/http"
"sync"
"github.com/labstack/echo/engine"
@ -14,7 +13,6 @@ import (
type (
Server struct {
*http.Server
config *engine.Config
handler engine.HandlerFunc
pool *Pool
@ -46,7 +44,6 @@ func NewTLS(addr, certfile, keyfile string) *Server {
func NewConfig(c *engine.Config) (s *Server) {
s = &Server{
Server: new(http.Server),
config: c,
pool: &Pool{
request: sync.Pool{
@ -92,7 +89,7 @@ func (s *Server) SetLogger(l logger.Logger) {
}
func (s *Server) Start() {
fasthttp.ListenAndServe(s.config.Address, func(c *fasthttp.RequestCtx) {
handler := func(c *fasthttp.RequestCtx) {
// Request
req := s.pool.request.Get().(*Request)
reqHdr := s.pool.requestHeader.Get().(*RequestHeader)
@ -114,6 +111,14 @@ func (s *Server) Start() {
s.pool.url.Put(reqURL)
s.pool.response.Put(res)
s.pool.responseHeader.Put(resHdr)
})
s.logger.Fatal(s.ListenAndServe())
}
addr := s.config.Address
certfile := s.config.TLSCertfile
keyfile := s.config.TLSKeyfile
if certfile != "" && keyfile != "" {
s.logger.Fatal(fasthttp.ListenAndServeTLS(addr, certfile, keyfile, handler))
} else {
s.logger.Fatal(fasthttp.ListenAndServe(addr, handler))
}
}

View File

@ -107,5 +107,12 @@ func (s *Server) Start() {
s.pool.response.Put(res)
s.pool.header.Put(resHdr)
})
s.logger.Fatal(s.ListenAndServe())
certfile := s.config.TLSCertfile
keyfile := s.config.TLSKeyfile
if certfile != "" && keyfile != "" {
s.logger.Fatal(s.ListenAndServeTLS(certfile, keyfile))
} else {
s.logger.Fatal(s.ListenAndServe())
}
}