Skip to content

Latest commit

 

History

History
52 lines (30 loc) · 2.59 KB

transport.md

File metadata and controls

52 lines (30 loc) · 2.59 KB

Transport

As grpc-web-client is an implementation of a binary protocol (gRPC) in browsers that have various methods of performing HTTP requests with varying implementations across vendors limitations there are multiple underlying transports that are used to provide support across browsers.

A “transport” in this context is a wrapper of one of these methods of creating a HTTP request (e.g. fetch or XMLHttpRequest).

How does grpc-web-client pick a transport?

You can specify the transport that you want to use for a specific invocation through the library property in the client, invoke and unary function options.

If a transport is not specified then a transport factory is used to determine the browser’s compatible transports. See Available Transports

If none are found then an exception is thrown.

Available transports

In order of attempted usage.

Fetch

Uses fetch. Requires that the browser supports Fetch with body.getReader.

Supports binary request and response bodies and allows streaming the response without buffering it entirely, thereby safely enabling long-lived server streams.

Supported by:

  • Chrome 43+
  • Edge 13+
  • Safari 10.1+

XMLHttpRequest (with moz-chunked-arraybuffer) (only available in Firefox)

Uses XmlHttpRequest (XHR) with responseType = "moz-chunked-arraybuffer" to enable reading the response stream chunks as binary as they arrive, rather than buffering the entire response as the standard XMLHttpRequest transport does, thereby safely enabling long-lived server streams.

Supported by:

  • Firefox 21+

XMLHttpRequest

Uses XmlHttpRequest (XHR) with overrideMimeType("text/plain; charset=x-user-defined"). overrideMimeType allows reading the string response as individual bytes as the response arrives.

Supported by:

  • Safari 6
  • IE 11

This transport is not safe for long-lived or otherwise large response streams as the entire server response is maintained in memory until the request completes.

Node HTTP (only available in a Node.js environment)

Uses http/https. This transport exists to allow usage of the grpc-web-client library in Node.js environments such as Electron or for server-side rendering.

Supported by:

  • Node.js only