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

[]byte in query now uses base64.StdEncoding #565

Merged
merged 1 commit into from
Mar 8, 2018

Conversation

lucasvo
Copy link
Contributor

@lucasvo lucasvo commented Mar 1, 2018

This fixes the issue with different base64 string encoding in query params and json representations in the request body discussed in #423

@loderunner Care to review?

Changed default encoding of []bytes in URL Query params to use standard
padded base64 encoding to be consistent with representation in json
serialized objects.
@googlebot
Copy link

Thanks for your pull request. t looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers
  • Your company has a Point of Contact who decides which employees are authorized to participate. Ask your POC to be added to the group of authorized contributors. If you don't know who your Point of Contact is, direct the project maintainer to go/cla#troubleshoot.
  • The email used to register you as an authorized contributor must be the email used for the Git commit. Check your existing CLA data and verify that your email is set on your git commits.
  • The email used to register you as an authorized contributor must also be attached to your GitHub account.

@lucasvo
Copy link
Contributor Author

lucasvo commented Mar 1, 2018

Signed the CLA.

@googlebot
Copy link

CLAs look good, thanks!

@loderunner
Copy link
Collaborator

Looks fine to me!

The burden will be on the client to correctly escape the query parameters to avoid /, + and =. I wonder if this is worth documenting somewhere. Perhaps someone from the grpc-gateway project can help us here?

@achew22
Copy link
Collaborator

achew22 commented Mar 7, 2018

Do either of you know if it is possible to use the same base64 en/decoder that is provided by golang/protobuf? How does the deserialization work when they are processing JSONified protos? Could you point me to the code where they do that?

@loderunner
Copy link
Collaborator

loderunner commented Mar 7, 2018

golang/protobuf uses the stdlib json encoding/decoding. The go structs generated from the proto file are annotated for JSON encoding.

Encoding byte slices to base64 is part of the stdlib:

Array and slice values encode as JSON arrays, except that []byte encodes as a base64-encoded string, and a nil slice encodes as the null JSON value.

Source

You can find the source for the encoding here and the decoding here

I think there is a bit of custom Marshal/Unmarshal code for handling enums and their string representations, but nothing for byte slices.

@achew22
Copy link
Collaborator

achew22 commented Mar 8, 2018

@loderunner, fantastic research! Thanks so much. comments like that make merging easy (and fun).

@lucasvo, thanks so much for finding the time to contribute to the project! I really look forward to working with you in the future.

@achew22 achew22 merged commit 463c5ed into grpc-ecosystem:master Mar 8, 2018
@lucasvo lucasvo deleted the bytes-base64 branch March 8, 2018 21:42
@lucasvo
Copy link
Contributor Author

lucasvo commented Mar 8, 2018

@loderunner did the heavy lifting, he deserves the credit! Thanks for helping out with this.

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

Successfully merging this pull request may close these issues.

4 participants