Skip to main content

Module call_context

Module call_context 

Source
Expand description

Call context for server-side interceptors.

CallContext carries metadata about the current JSON-RPC or REST call, allowing ServerInterceptor implementations to make access-control and auditing decisions.

§HTTP headers

The http_headers field carries the raw HTTP request headers (lowercased keys, last-value-wins for duplicates). This enables interceptors to inspect Authorization, X-Request-ID, or any other header without coupling the SDK to a specific HTTP library.

use a2a_protocol_server::CallContext;

let ctx = CallContext::new("SendMessage")
    .with_http_header("authorization", "Bearer tok_abc123")
    .with_http_header("x-request-id", "req-42");

assert_eq!(ctx.http_headers().get("authorization").map(String::as_str),
           Some("Bearer tok_abc123"));

§The peer’s address

peer_addr is the address of the connection the call arrived on. It travels in the headers map under PEER_ADDR_KEY, as the request path does under ":path": a real header cannot carry either name, since a colon is not valid in an HTTP field name or a gRPC metadata key, so a client cannot supply them. Each binding sets it when the server knows the address:

  • JSON-RPC and REST: from the PeerAddr request extension, which Server inserts (and so do the deprecated serve and serve_with_addr, which run on it). A server of your own that calls Dispatcher::dispatch inserts it the same way.
  • The axum router: from PeerAddr, or from axum’s ConnectInfo<SocketAddr> when it is served with into_make_service_with_connect_info::<SocketAddr>().
  • WebSocket and gRPC: from the accepted TCP stream.

Behind a reverse proxy this is the proxy’s address. The client’s is in x-forwarded-for, which only the deployment knows how far to trust.

§The peer’s certificate

peer_certificate is the certificate the client presented in a mutual-TLS handshake on the listener itself, the leaf of its chain, DER-encoded. The TLS configuration’s client verifier has already checked it against the CAs it trusts; this is the certificate it accepted. It travels under PEER_CERTIFICATE_KEY, base64, for the same reason the address does, and is set from:

  • JSON-RPC and REST: the PeerCertificate request extension, which Server::with_tls inserts on a connection whose client presented one.
  • The axum router: PeerCertificate, when the server it runs on inserts it.
  • WebSocket: its TLS listener’s handshake. gRPC: tonic’s, under grpc-tls.

MutualTlsAuthInterceptor (tls-rustls or grpc-tls) names the caller from it. A TLS-terminating proxy in front of the listener means there is none: the proxy’s own handshake is the one the listener sees.

Structs§

CallContext
Metadata about the current server-side method call.
PeerAddr
The address of the connection a request arrived on, as an HTTP request extension.
PeerCertificate
The certificate a client presented in the TLS handshake of the connection a request arrived on, DER-encoded, as an HTTP request extension; see the module docs.

Constants§

PEER_ADDR_KEY
The headers-map key under which a binding records the address of the connection a call arrived on, as ip:port; see CallContext::peer_addr.
PEER_CERTIFICATE_KEY
The headers-map key under which a binding records the client’s mutual-TLS certificate, standard base64 of its DER encoding; see CallContext::peer_certificate.