Coder Social home page Coder Social logo

Why grpc-gateway mode is base64? about grpc-web HOT 4 CLOSED

grpc avatar grpc commented on July 17, 2024
Why grpc-gateway mode is base64?

from grpc-web.

Comments (4)

stanley-cheung avatar stanley-cheung commented on July 17, 2024

Two major reasons:

  1. To support streaming, we need to be able to read the partial data being sent from the server (with the Transfer-Encoding: chunked HTTP header). But for now, the underlying XHR implementation does not support reading partial binary data. See https://hpbn.co/xmlhttprequest/

Partial response can be read only from the responseText attribute, which limits us to text-only transfers. There is no way to read partial response of a binary transfer.

  1. We sent trailing metadata as a separate message at the end, basically using the same Transfer-Encoding: chunked mechanism. We don't want to have to wait for the entire trailers to be sent before the client can read the 'response'.

from grpc-web.

sulliwane avatar sulliwane commented on July 17, 2024

Ok, the reading about XHR is interesting, I understand better now.

Regarding your second point, could you be more specific when saying

"sending trailing metadata as a separate message at the end"

Because in this other thread, I'm trying to manually decode the base64 response to a protobuf message. I correctly receive the whole response (as a base64 string), but when deserizalizing, I get all the data in the same Message field, with many scrambled character...

screenshot from 2017-03-29 11-22-11

Could it be the result of these metadata being mixed with the protobuf message response?

Many thanks!

from grpc-web.

mwitkow avatar mwitkow commented on July 17, 2024

@stanley-cheung please talk to @MarcusImprobable. We solved it using xhr.responseType = "text" and this magical byte mapping hack:
https://github.com/improbable-eng/grpc-web/blob/master/ts/src/transports/xhr.ts#L4

Seems to work on Safari, which is the new IE ;)

from grpc-web.

wenbozhu avatar wenbozhu commented on July 17, 2024

@sulliwane The current github release is a pre-alpha release, with the core shared with our internal release. If you don't mind, let's focus on the API (feedback) rather than the implementation detail for the JS client (which will be updated frequently before beta).

Thanks for all the feedback!

===

@mwitkow Yes, I have looked at this and we will evaluate the xhr hack which would be a great optimization. We also need make grpc-web client works across all browsers (inc. mobile browsers).

Re: base64, it is also required for serving binary responses from cookie domains (to prevent XSS etc).

from grpc-web.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.