Skip to main content

Crate grpc_webnext

Crate grpc_webnext 

Source
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 Codec that 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.http transcoding: 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 +json codec.
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 +json termination.
transcode
JSON <-> protobuf transcoding for the +json codec.

Structs§

ProxyConfig
Configuration for serve_proxy — front a remote upstream gRPC server.
ServerConfig
Configuration for serve_in_process — wrap an in-process tonic service.

Enums§

FetchError

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-timeout downstream 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 +proto unary 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 routes on listener.
serve_proxy
Serve grpc-webnext + native gRPC passthrough in front of an upstream gRPC server.
ws_subprotocols
Parse the Sec-WebSocket-Protocol request header into its comma-separated tokens. Used to negotiate the codec / detect the h2ts subprotocol at handshake time.

Type Aliases§

BoxError
ResBody