Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use decodeGrpcWebBody #11

Open
ivan-rodriguez-ag opened this issue Jul 11, 2023 · 3 comments
Open

How to use decodeGrpcWebBody #11

ivan-rodriguez-ag opened this issue Jul 11, 2023 · 3 comments

Comments

@ivan-rodriguez-ag
Copy link

ivan-rodriguez-ag commented Jul 11, 2023

Hi,

I am building mock server with express and i am using your library to serialize and deserialize proto objects but now i am facing a problem to deserialize the request body of a proto in the express server.

My idea Is to read the body string (something like this AAAAAAMKATE=) and use your function to decode

decodeGrpcWebBody(Buffer.from('AAAAAAMKATE='))

But i get the following error: throw new Error("Unrecognised status code [".concat(status, "]"));

I tried:

decodeGrpcWebBody(Buffer.from('AAAAAAMKATE=', 'base64'));

but in this case i had the error: throw new Error("Expected trailers header 0x80");

Is it right to get the string and generate a buffer from the string? Should i read the express body as buffer?

I am completely lost about what is happening here, i don't know if you have some clue

Thanks

@zakhenry
Copy link
Contributor

Since your string appears to be base64 encoded your second attempt looks more promising to me.

How did you get the body string in the first place? The error "Expected trailers header 0x80" suggests to me that you might not be getting the expected body format that this library was designed for (the grpc-web protocol)

@ivan-rodriguez-ag
Copy link
Author

In my case i read the body of the request (this contains the string i shared) that is the one that grpc-web send for the requests. I think the problem is that i am trying to decode any Message from grpc-weband maybe this decoder id built for specific signature? Because i'll need to tell the deserializer the class to use if not i'll recieve a binary or something similar i guess

@zakhenry
Copy link
Contributor

Yea so if your body message is of the expected format, you will get a GrpcResponse type back

This contains the message which itself is a bytearray that you would use one of your protobuf messages to decode. So to clarify decodeGrpcWebBody does not turn a http message body into a javascript representation of your proto object, rather it parses the specific syntax of the grpc-web protocol so that you get your hands on the bytes to then parse with the generated protos.

Are you using playwright though? I wouldn't expect direct usage of decodeGrpcWebBody to be necessary if so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants