hyperium / tonic

A native gRPC client & server implementation with async/await support.
https://docs.rs/tonic
MIT License
9.81k stars 998 forks source link

Malformed response for non `Ok` statuses when using `web_tonic` on the server. #1666

Open cyanic-selkie opened 6 months ago

cyanic-selkie commented 6 months ago

Bug Report

Version

tonic 0.11.0 tonic_web 0.11.0 tonic_web_wasm_client 0.5.1

Platform

Linux zb 6.8.1-arch1-1 #1 SMP PREEMPT_DYNAMIC Sat, 16 Mar 2024 17:15:35 +0000 x86_64 GNU/Linux

Description

I switched from using the traefik reverse proxy for the grpc-web translation layer to the tonic_web crate by simply adding the .accept_http1(true) and .layer(GrpcWebLayer::new()) calls to the server builder. When I'm using traefik, everything works fine.

Using tonic_web, when Ok responses are returned, everything works fine. However, when a non Ok status is returned (e.g., Internal or NotFound), I get the following error on the client:

Error: Status { code: Unknown, message: "malformed response", metadata: MetadataMap { headers: {"content-length": "0", "content-type": "application/grpc-web+proto"} }, source: Some(MalformedResponse) }!

I am using the unofficial tonic_web_wasm_client since I couldn't get the tonic_web client working, as the example is outdated, and I couldn't figure out what to use instead of the hyper::Client object. Since it is working with the traefik proxy, I'm guessing the issue is in the new translation layer, not the client crate.