Add support for gRPC-Web text encoding #150
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds support for gRPC-Web's text encoding to handle
application/grpc-web-text
content types. Only client support is added for now, for simplicity. Encoding of request and response body is handled to support text streams. Testing is added by mutating a gRPC-Web client to implement the text protocol.The implementation is done by converting the request body and response writer to encode and decode streams of base64 encoded data. Go's std library cannot handle padding characters within the stream. For writing base64 encoded data we can simply use
base64.NewEncoder
, callingClose
when needed to flush data to the writer. To read base64 encoded data we cannot usebase64.NewDecoder
as we need to split the reader on padding characters to form valid base64 chunks to pass to the decoder. Therefore this implementation buffers the stream into 4-byte tokens before decoding, splitting on padding tokens when found.Closes #143