soheilhy / cmux

Connection multiplexer for GoLang: serve different services on the same port!
Apache License 2.0
2.53k stars 197 forks source link

Advice for cmux TLS gRPC + plaintext http/1 #60

Open jamisonhyatt opened 6 years ago

jamisonhyatt commented 6 years ago

Are there material downsides to supporting TLS gRPC + plaintext http using a configuration as below?

listener, _ := net.Listen("tcp", fmt.Sprintf("0.0.0.0:%v", port))

combinedMux := cmux.New(listener)
routeListener := combinedMux.Match(cmux.HTTP1Fast())
grpcListener := combinedMux.Match(cmux.Any())

creds, _ := credentials.NewServerTLSFromFile(   serverPemFilePath, serverKeyFilePath)
grpcServer := grpc.NewServer(grpc.Creds(creds)...)

routeMux := http.NewServeMux()
routeMux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
    //some handler
}
s := &http.Server{
    Handler: routeMux,
}

go  grpcServer.Serve(grpcListener)

go s.Serve(routeListener)

combinedMux.Serve()