Allow tonic-web to forward gRPC traffic over HTTP/1.1
- Dominant language
- Rust
- Stars
- 12.5k
- Forks
- 1.3k
- Avg merge
- 4d 7h
- Merged PRs (30d)
- 24
Description
## Feature Request
### Crates
`tonic-web`
### Motivation
Right now, `tonic-web`'s `GrpcWebService` tower service [explicitly checks and denies](https://github.com/hyperium/tonic/blob/v0.9.2/tonic-web/src/service.rs#L118-L133) any non-grpc-web (regular gRPC) traffic that's not sent over HTTP/2. However, `tonic` (and `hyper`) itself are fine with accepting gRPC traffic over HTTP/1.1 (via `tonic::transport::Server::accept_http1`).
While I can agree that gRPC should ideally communicate over HTTP/2, I've run into the situation where a proxy between the gRPC client and server only speaks HTTP/1.1 to the upstream (the tonic server). This makes it impossible to speak HTTP/2 to tonic. Tonic behaves completely correctly in this situation, _unless_ `GrpcWebServer` is part of the tower stack, in which case all requests return `HTTP 400`.
### Proposal
`GrpcWebService` should have a flag that controls whether or not non-HTTP/2 traffic is allowed through the tower stack when a request is not a grpc-web request. This is backwards-compatible, as existing methods on `tonic-web` do not need to change, and the default behaviour can be to deny HTTP/1.*. This looks easy to implement, but I'd like the approval of maintainers first.
### Alternatives
I am currently working around this by creating another tower service that wraps `GrpcWebService` and skips it if the content type for a request is not `application/grpc-web*`. It's resulted in a lot of boilerplate for a simple operation, so having the functionality built into `GrpcWebService` would be much preferred.
Contributor guide
Assessment
This issue has not been assessed yet.