devashishdxt / tonic-web-wasm-client

Other
104 stars 28 forks source link

"missing content-type header in grpc response" error despite it being present #53

Closed filtoid closed 1 year ago

filtoid commented 1 year ago

I've put together a simple example of the problem I'm facing (which is probably user error, but I'm afraid I'm completely stumped as to what might be causing it). The example can be found here: https://github.com/filtoid/tonic-web-wasm-client-example

This sets up a simple server using Tonic and a simple front end in Yew, which uses tonic-web-wasm-client to make the request to the server. The response causes the library to throw the following error:

error received while calling service:  status: Unknown, message: "missing content-type header in grpc response", details: [], metadata: MetadataMap { headers: {} }

Which appears to imply the server is not replying with a response, however from inspecting in the browser network tab it seems to show that it did succeed and returned a valid header for content-type (albeit not an accepted one, but I've tried forcing the content-type to the "accept"ed version and it still responded in this way. In Firefox it shows that no body was returned - however in Edge and Safari it shows a body:

image

image

Any advice you can give me on how to proceed would be very gratefully received but I've tried linking the lib locally and putting some tracer statements in, and the only thing I can see is what appears to be the response just being "lost" somehow, as the browser sees it but the library can not.

devashishdxt commented 1 year ago

Hi. I think you're creating a normal grpc server without adding support for grpc-web. You need to use tonic-web to do this.

Here's an example for this: https://github.com/devashishdxt/tonic-web-wasm-client/tree/main/test-suite/simple/server

filtoid commented 1 year ago

Ah, thanks I shall have a go at that then - I thought I might be doing something wrong.

filtoid commented 1 year ago

Thanks in part to your linked suggestion I have realised that tonic-web doesn't work when NoCors is set on the client. I shall update the code with the fixed version and push.