Expand description
grpc-webnext: serve the grpc-webnext wire protocol (unary over Fetch, streaming over
WebSocket, plus +json / REST transcoding) over any gRPC service.
All the inbound protocol translation is shared; the only thing that varies is where the
translated gRPC call lands — a local in-process tonic::service::Routes you own
(serve_in_process, the “native server” / wrap mode) or a remote upstream over an
HTTP/2 channel (serve_proxy, the standalone binary proxy). Both are the same
Backend; the two entry points build one and run the identical handlers, so a client
can’t tell a wrapped response from a proxied one.
Re-exports§
pub use backend::Backend;pub use schema::Schema;pub use schema::SchemaSource;pub use codec::BytesCodec;pub use frame::decode_frame;pub use frame::encode_frame;pub use frame::FrameError;pub use grpc_framing::deframe_all;pub use grpc_framing::frame as grpc_frame;pub use grpc_framing::Deframer;pub use httprule::HttpCall;pub use httprule::HttpRouter;pub use httprule::WsBinding;pub use transcode::TranscodeError;pub use transcode::Transcoder;
Modules§
- backend
- The gRPC dispatch target.
- codec
- A tonic
Codecthat passes message bytes through untouched. - frame
- Encode/decode a single WebSocket
Frame(one frame per WS message). - grpc_
framing - gRPC wire message framing:
[1-byte compression flag][4-byte big-endian length][message bytes]. - httprule
google.api.httptranscoding: map REST-style(HTTP method, path)requests onto gRPC methods, binding path segments, query params, and the request body into the request message.- json_
frame - Native-JSON WebSocket frame format for the
+jsoncodec. - metadata
- HTTP header <-> gRPC metadata conversion, protobuf metadata <-> gRPC metadata conversion, and grpc-timeout parsing. Shared by the proxy and the native server library.
- pb
- schema
- Descriptor source for
+jsontermination. - transcode
- JSON <-> protobuf transcoding for the
+jsoncodec.
Structs§
- Proxy
Config - Configuration for
serve_proxy— front a remote upstream gRPC server. - Server
Config - Configuration for
serve_in_process— wrap an in-process tonic service.
Enums§
Constants§
- CT_JSON
- CT_
PROTO - DEADLINE_
GRACE - The proxy owns the client-facing deadline: it drops the call at the deadline
(surfacing DEADLINE_EXCEEDED) and forwards
grpc-timeoutdownstream with this grace so the callee’s own enforcement is a later backstop rather than racing the local timer. - EMPTY_
MESSAGE_ BLOCK - The empty message block (
[u32 len = 0]): a trailers-only response (an error with no message) still needs the leading message block before the trailer block. - LEN_
PREFIX - WS_
SUBPROTOCOL - Base subprotocol; a client offers it plus a codec/credential entry.
- WS_
SUBPROTOCOL_ JSON - WS_
SUBPROTOCOL_ PROTO
Functions§
- bind_
and_ serve_ in_ process - Bind an ephemeral local address, serve an in-process
routes, and return the bound address + task handle. For tests and simple mains. - bind_
and_ serve_ proxy - Bind an ephemeral local address, serve a proxy, and return the bound address + handle.
- decode_
response_ body - Decode a buffered unary response body into
(message bytes, Trailer). - encode_
request_ body - Encode a
+protounary request body: a single[u32 len | message]block, mirroring the response’s message block. The client prepends the length it already knows (protobuf is serialized whole), so the server/proxy can turn it into a gRPC frame —[1-byte flag]+ this — and stream it upstream without buffering to measure. - encode_
response_ body - Encode a unary response body from the message bytes and its trailer.
- encode_
trailer_ block - Encode just the trailing
[u32 len | Trailer bytes]block. Used by the streaming response path, which forwards the message block straight from the inner gRPC frame (its[u32 len | message]layout already matches ours once the 1-byte compression flag is dropped) and only needs to append this at the end. - serve_
in_ process - Serve grpc-webnext + native gRPC for an in-process
routesonlistener. - serve_
proxy - Serve grpc-webnext + native gRPC passthrough in front of an upstream gRPC server.
- ws_
subprotocols - Parse the
Sec-WebSocket-Protocolrequest header into its comma-separated tokens. Used to negotiate the codec / detect theh2tssubprotocol at handshake time.