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

Add support for gRPC-Web text encoding #150

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

emcfarlane
Copy link
Collaborator

@emcfarlane emcfarlane commented Nov 9, 2024

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, calling Close when needed to flush data to the writer. To read base64 encoded data we cannot use base64.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

This adds support for gRPC-Web's text encoding. Only client support
is added. Encoding of request and response body is handled to support
text streams.

Signed-off-by: Edward McFarlane <emcfarlane@buf.build>
@emcfarlane emcfarlane requested a review from jhump November 9, 2024 20:37
Signed-off-by: Edward McFarlane <emcfarlane@buf.build>
Signed-off-by: Edward McFarlane <emcfarlane@buf.build>
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

Successfully merging this pull request may close these issues.

Feature Request: grpc-web-text wire format support
1 participant