An attempt at hosting HTTP/1.1, HTTP/2 and gRPC on the same port(s).
Multiple Hyper servers are spawned on different endpoints to showcase the use of binding to different IP addresses
and ports while reusing the same server components. A Hyper service is used to switch the incoming traffic based on the
content-type
header and if application/grpc
is detected, traffic is forwarded to the Tonic server; all other
cases forward to Axum. This allows for transparent use of HTTP/1.1 and HTTP/2 (prior knowledge), as well
as ALPN on the TLS-enabled ports. On Unixoids, Unix Domain Sockets are supported as well.
This project uses:
- Hyper as the server for HTTP/1 and HTTP/2 support.
- tls-listener with tokio-rustls is used to provide TLS with
h2
andhttp/1.1
ALPN support.
- tls-listener with tokio-rustls is used to provide TLS with
- Axum as the HTTP server.
- Tonic as the gRPC server.
curl -v http://127.0.0.1:36849/
curl -v http://127.1.0.1:36849/
curl --http2-prior-knowledge --insecure -vv http://127.0.0.1:36849/
curl -v --unix-socket /tmp/cohosting.sock http://localhost:36849/
curl --insecure -v https://127.0.0.1:36850/
curl --http1.1 --insecure -vv https://127.0.0.1:36850/
curl --http2 --insecure -vv https://127.0.0.1:36850/
nghttp -v http://127.0.0.1:36849
nghttp -y -v https://127.0.0.1:36850
Use gRPC reflection to introspect the service:
grpcurl --plaintext --use-reflection 127.0.0.1:36849 list
grpcurl --insecure --use-reflection 127.0.0.1:36850 list
Send a test request:
grpcurl --plaintext --use-reflection -d '{ "message": "World" }' 127.0.0.1:36849 example.YourService/YourMethod
grpcurl --insecure --use-reflection -d '{ "message": "World" }' 127.0.0.1:36850 example.YourService/YourMethod
For UDS to work with gRPC, the :authority
header needs to be sent. In grpcurl
, the --authority=xyz
flag
is used for that:
grpcurl --unix --plaintext --use-reflection --authority localhost -d '{ "message": "World" }' /tmp/cohosting.sock example.YourService/YourMethod
The Combining Axum, Hyper, Tonic, and Tower for hybrid web/gRPC apps series: