Expand description
gRPC-Web framing translation and JSON-to-gRPC transcoding (DW-101).
§gRPC-Web framing
gRPC-Web is the browser-friendly variant of gRPC: it replaces HTTP/2 trailers with a trailing frame that carries the gRPC status as pseudo-headers, and it frames every chunk with a 5-byte prefix (1 byte flag + 4 bytes big-endian length). The flag byte distinguishes data frames (0x00) from trailer frames (0x80). A unary response is one data frame followed by one trailer frame; a streaming response is an arbitrary number of data frames (each its own 5-byte-prefixed chunk) followed by a single trailer frame.
The gateway sits between a browser (gRPC-Web) and a native gRPC upstream (HTTP/2 + trailers). On the forward path it strips the gRPC-Web framing and reconstructs the native gRPC request body; on the response path it wraps the native gRPC frames (data + trailers) back into gRPC-Web framing so the browser can decode them.
§JSON-to-gRPC transcoding
When transcoding is enabled, the gateway also accepts plain JSON
requests (Content-Type: application/json) and translates them to
protobuf wire bytes for the upstream, and translates the protobuf
response back to JSON. The mapping is driven by .proto descriptors
supplied via config (FileDescriptorSet files): at config publish the
gateway loads the descriptors, builds a method map keyed by the
fully-qualified gRPC method name
(/{package}.{service}/{method}), and resolves each method’s
request and response message types. The google.api.http annotation
on each RPC maps an HTTP path + verb to the gRPC method, so a REST
or JSON client can call a gRPC backend without a gRPC library.
§gRPC status mapping
A gRPC status (carried in the grpc-status trailer) is mapped to an
HTTP status code and a google.rpc.Status JSON body for non-gRPC
clients. The mapping follows the gRPC HTTP/JSON specification (the
google.rpc.Code -> HTTP status table).
§Status
The module compiles into every build (no cargo feature). The config
schema (GrpcWeb, GrpcWebTranscoding, GrpcWebDescriptor) parses
and validates; the runtime framing/transcoding translation is
scaffolded and not yet dispatched from the request path.
Modules§
- field_
label - Field label constants (the
FieldDescriptorProto.Labelenum). - field_
type - Field type constants (the
FieldDescriptorProto.Typeenum). - grpc_
code - gRPC status codes (the
google.rpc.Codeenum values).
Structs§
- Descriptor
Proto google.protobuf.DescriptorProto— a message type.- Enum
Descriptor Proto google.protobuf.EnumDescriptorProto— an enum type.- Enum
Value Descriptor Proto google.protobuf.EnumValueDescriptorProto— one enum value.- Field
Descriptor Proto google.protobuf.FieldDescriptorProto— one field in a message.- File
Descriptor Proto google.protobuf.FileDescriptorProto— one .proto file.- File
Descriptor Set google.protobuf.FileDescriptorSet— the top-level container produced byprotoc --descriptor_set_out.- Grpc
Transcoder - The gRPC-Web + JSON transcoding engine. Loaded at config publish from .proto descriptor files; holds a method map keyed by the fully- qualified gRPC method path.
- Loaded
Descriptor - A loaded .proto descriptor entry: the raw FileDescriptorSet bytes plus the package and service names that identify the methods this descriptor covers.
- Method
Descriptor Proto google.protobuf.MethodDescriptorProto— one RPC method.- Method
Info - A resolved gRPC method: its fully-qualified path and the request/ response message type names.
- Service
Descriptor Proto google.protobuf.ServiceDescriptorProto— an RPC service.
Enums§
- Grpc
WebError - Errors from gRPC-Web framing translation or JSON-to-gRPC transcoding.
Functions§
- build_
trailers - Build a trailer byte payload from a map of key-value pairs, in the
key: value\nformat gRPC-Web expects. - grpc_
status_ name - The gRPC status name for a code (for logging / trailer display).
- grpc_
status_ to_ http - Map a gRPC status code to an HTTP status code and a
google.rpc.StatusJSON body. The JSON body follows thegoogle.rpc.Statusshape:{ "code": <int>, "message": "<string>", "details": [] }. - parse_
trailers - Parse the gRPC-Web trailer frame payload (key: value lines) into a map. Returns an empty map for an empty payload.
- translate_
grpc_ to_ grpc_ web - Wrap native gRPC response bytes in gRPC-Web framing.
- translate_
grpc_ to_ grpc_ web_ data_ chunk - Wrap a single gRPC data chunk in a gRPC-Web data frame (no trailer
frame). Used for streaming responses where each upstream data frame
becomes its own gRPC-Web data frame, and the trailer frame is sent
once at stream end via
translate_grpc_trailers_to_grpc_web. - translate_
grpc_ trailers_ to_ grpc_ web - Wrap gRPC trailers in a gRPC-Web trailer frame. Sent as the final frame of a streaming gRPC-Web response.
- translate_
grpc_ web_ to_ grpc - Strip gRPC-Web framing and reconstruct the native gRPC request body.