livery_grpc_web (livery_grpc v0.1.1)

View Source

gRPC-Web framing.

gRPC-Web carries the same length-prefixed messages as gRPC, but the status travels in the response body, not in HTTP trailers, so it works over HTTP/1.1 and through browsers. The trailers are sent as a final frame whose flag byte has the high bit set (0x80); its payload is an HTTP/1.1-style name:value\r\n block.

Two content types: application/grpc-web[+proto] is binary; application/grpc-web-text base64-encodes the whole body (request and response). This module classifies the request content type and provides the trailer frame plus the text base64 transforms.

Summary

Functions

The response content-type for a mode.

Decode a request body for a mode: base64 first for the text variant.

Encode a full response body for a mode: base64 for the text variant.

Whether a mode is one of the gRPC-Web variants.

Classify a request content-type into a mode, or undefined if it is not a gRPC family type.

Build the gRPC-Web trailer frame from a status header list (as livery_grpc_status:trailers/1,2 returns). The frame flag is 0x80.

Types

mode()

-type mode() :: grpc | grpc_web | grpc_web_text.

Functions

content_type/1

-spec content_type(mode()) -> binary().

The response content-type for a mode.

decode_request/2

-spec decode_request(mode(), binary()) -> binary().

Decode a request body for a mode: base64 first for the text variant.

encode_body/2

-spec encode_body(mode(), iodata()) -> binary().

Encode a full response body for a mode: base64 for the text variant.

is_web/1

-spec is_web(mode()) -> boolean().

Whether a mode is one of the gRPC-Web variants.

mode/1

-spec mode(binary() | undefined) -> mode() | undefined.

Classify a request content-type into a mode, or undefined if it is not a gRPC family type.

trailer_frame(StatusHeaders)

-spec trailer_frame([{binary(), binary()}]) -> binary().

Build the gRPC-Web trailer frame from a status header list (as livery_grpc_status:trailers/1,2 returns). The frame flag is 0x80.