Why do browsers not support gRPC?

2019-03-22 04:13发布

gRPC is based on HTTP/2, which (assumption) is widely supported by browsers. Therefore, I feel there should be no problem with gRPC from a browser.

However, it is clear that there is a problem. The protocol, grpc web, is different, as exists "due to browser limitation". There are also numerous blog post describing complicated tech stacks deployed to get gRPC to work from a browser.

I'm missing the actual problem - why does gRPC not simply work from browsers?

标签: grpc grpc-web
2条回答
再贱就再见
2楼-- · 2019-03-22 04:40

I now understand that browsers only supports HTTP/2 in the sense that they use it to fetch resources from the server on behalf of your application (javascript) code.

Javascipt application code can still only use HTTP/1 (which may be handled under the hood by the browser in an HTTP/2 connection). Therefore it is not possible for application code to use grpc.

If anyone should find where this is explained in the docs, it would be good to add a link to it here.

查看更多
smile是对你的礼貌
3楼-- · 2019-03-22 04:48

Most browsers use HTTP1.1 whereas GRPC only works with HTTP2. You can use nginx, envoy or traefic to run it behind a reverse proxy, very similar to how web sockets are often used behind a reverse proxy(in that case the http1 is upgraded to a websockets connection). The reverse proxy will send the grpc request sent over http1 to an http2 backend and vice versa. You can use Envoy(suggested/currently used by grpc-web), traefik(am using this personally) and nginx.

查看更多
登录 后发表回答