soheilhy/cmux

Cannot get Matchers to mux h2c gRPC and HTTP2(REST) requests

Liu-Chunhui opened this issue · 4 comments

Hi there,

Situration: my project is running in istio + k8s. When the http1.1 requests comes into the istio, it will be upgraded to http2 and passed to k8s pod. Also, I need to run non-tls gRPC and HTTP server on the same port, e.g. :9000

Issue: I try to use cmux to create machers to split grpc and rest requests but i am failed.

Could you please provide an example to achieve that?

Thanks,

see my explain #79

I think the issue you will find here is that your gRPC requests and HTTP2 requests are likely multiplexed over the same connection. cmux does matching at the connection level, so you end up with detecting one way or the other based on the first request, then all future requests are locked to whatever was originally matched.

You can use cmux.HTTP2MatchHeaderFieldSendSettings("content-type, "application/grpc") match gRPC first, and then use cmux.Any match other proto and create new listener for new cmux.CMux

I was unable to get it to work with cmux, h2 REST would always fail to connect

I ended up following a similar approach to this:
https://ahmet.im/blog/grpc-http-mux-go/
For my use case this ended up working (http1.1, h2 REST and grpc all work as expected)