Parsing of grpc-web trailers is incorrect
See original GitHub issueAnd the docs for String#split()
Limit - A non-negative integer specifying a limit on the number of substrings to be included in the array. If provided, splits the string at each occurrence of the specified
separator
, but stops whenlimit
entries have been placed in the array. Any leftover text is not included in the array at all.
This means that a response trailer that looks like this
grpc-status:9
grpc-message:Precondition failed for updated time (actual: 1633092892, expected: 1633092890)
Will result in an error being thrown like this: RpcError: Precondition failed for updated time (actual
The official grpc-web client parses the trailers with https://github.com/grpc/grpc-web/blob/3956560ad01b4af0a2a5c29c081f5bbd1424e85d/javascript/net/grpc/web/grpcwebclientreadablestream.js#L349-L358 where it finds the first index of :
, everything before that is key
and everything after is value
.
This seems like an easy fix. I’ll try to put up a PR to address this over the weekend.
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (10 by maintainers)
Top GitHub Comments
😅 I was working on it this weekend. I don’t quite have a PR ready for you yet, but here are a few things I’ve noticed already:
"sourceMap": true
to tsconfig.test.json fixes the coverage report which made finding the areas missing coverage much easier.Response
, any duplicate entries (keys) will have their values.join(', ')
-ed automatically so checking for any array is only necessary for parsing the trailers. https://github.com/timostamm/protobuf-ts/blob/12098410d02c9af3c8f9cf5e477cc4dd576ffbfa/packages/grpcweb-transport/src/grpc-web-format.ts#L275-L277Ha, so it doesn’t even do as I was arguing?
From the manual:
Apparently not, sorry about the confusion. gRPC clients for C# do behave like I argued, and
@grpc/grpc-js
does so as well, but it looks like I just pondered changing our implementation, and didn’t go forward with it. Changing theresponse
promise to reject would definitely be a breaking change, so let’s hold on moving this.FYI: Going through your PR at the moment (huge thanks in advance).