From 5e87b33b23cfac1ae252ca046eb5eefc33a49a08 Mon Sep 17 00:00:00 2001 From: kevin Date: Thu, 29 Oct 2020 17:44:51 +0800 Subject: [PATCH] support https in rest --- rest/config.go | 10 ++++++---- rest/engine.go | 6 +++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/rest/config.go b/rest/config.go index d3a09330..f9aaf4d9 100644 --- a/rest/config.go +++ b/rest/config.go @@ -18,7 +18,7 @@ type ( PrivateKeys []PrivateKeyConf } - // why not name it as Conf, because we need to consider usage like: + // Why not name it as Conf, because we need to consider usage like: // type Config struct { // zrpc.RpcConf // rest.RestConf @@ -28,9 +28,11 @@ type ( service.ServiceConf Host string `json:",default=0.0.0.0"` Port int - Verbose bool `json:",optional"` - MaxConns int `json:",default=10000"` - MaxBytes int64 `json:",default=1048576,range=[0:8388608]"` + CertFile string `json:",optional"` + KeyFile string `json:",optional"` + Verbose bool `json:",optional"` + MaxConns int `json:",default=10000"` + MaxBytes int64 `json:",default=1048576,range=[0:8388608]"` // milliseconds Timeout int64 `json:",default=3000"` CpuThreshold int64 `json:",default=900,range=[0:1000]"` diff --git a/rest/engine.go b/rest/engine.go index a7f499a3..a39547f1 100644 --- a/rest/engine.go +++ b/rest/engine.go @@ -65,7 +65,11 @@ func (s *engine) StartWithRouter(router httpx.Router) error { return err } - return internal.StartHttp(s.conf.Host, s.conf.Port, router) + if len(s.conf.CertFile) == 0 && len(s.conf.KeyFile) == 0 { + return internal.StartHttp(s.conf.Host, s.conf.Port, router) + } + + return internal.StartHttps(s.conf.Host, s.conf.Port, s.conf.CertFile, s.conf.KeyFile, router) } func (s *engine) appendAuthHandler(fr featuredRoutes, chain alice.Chain,