etcdmain: handle TLS in grpc-proxy listener

release-3.1
Gyu-Ho Lee 2016-11-21 10:39:34 -08:00
parent 0326d6fdd3
commit ff96769b55
No known key found for this signature in database
GPG Key ID: 1DDD39C7EB70C24C
1 changed files with 9 additions and 2 deletions

View File

@ -15,6 +15,7 @@
package etcdmain
import (
"crypto/tls"
"fmt"
"net"
"net/http"
@ -119,7 +120,6 @@ func startGRPCProxy(cmd *cobra.Command, args []string) {
pb.RegisterLeaseServer(server, leasep)
pb.RegisterMaintenanceServer(server, mainp)
pb.RegisterAuthServer(server, authp)
grpc_prometheus.Register(server)
errc := make(chan error)
@ -132,7 +132,14 @@ func startGRPCProxy(cmd *cobra.Command, args []string) {
srvhttp := &http.Server{
Handler: httpmux,
}
httpl := m.Match(cmux.HTTP1())
var httpl net.Listener
if cfg.TLS != nil {
srvhttp.TLSConfig = cfg.TLS
httpl = tls.NewListener(m.Match(cmux.Any()), cfg.TLS)
} else {
httpl = m.Match(cmux.HTTP1())
}
go func() { errc <- srvhttp.Serve(httpl) }()
go func() { errc <- m.Serve() }()