GrpcServerCallScope

Available in a dev version: 0․11․0-grpc-186

How to configure

The scope of a single incoming gRPC server call observed by a GrpcServerInterceptor.

An interceptor receives this scope instance for every RPC invocation arriving to the server and can:

  • Inspect the target RPC method.

  • Read client-provided requestHeaders.

  • Populate responseHeaders (sent before the first response message) and responseTrailers (sent when the call completes).

  • Register a completion callback with onClose.

  • Abort the call early with close.

  • Continue handling by calling proceed with the inbound request Flow and optionally transform the returned response Flow.

Type Parameters

Request

the request message type of the RPC.

Response

the response message type of the RPC.

Properties

Link copied to clipboard
abstract val context: GrpcContext

The GrpcContext associated with this call.

Link copied to clipboard

Descriptor of the RPC method (name, marshalling, type) being executed.

Link copied to clipboard

Metadata received from the client with the initial request headers. Read-only from the server perspective.

Link copied to clipboard

Initial response headers to be sent to the client. Interceptors and handlers may add entries before the first response element is emitted (i.e., before proceeding or before producing output), otherwise headers might have already been sent.

Link copied to clipboard

Trailing metadata to be sent with the final status when the call completes. Interceptors can add diagnostics or custom metadata here.

Functions

Link copied to clipboard
abstract fun close(status: GrpcStatus, trailers: GrpcMetadata = GrpcMetadata()): Nothing

Immediately terminate the call with the given status and optional trailers.

Link copied to clipboard
abstract fun onClose(block: (GrpcStatus, GrpcMetadata) -> Unit)

Register a callback invoked when the call is closed (successfully or exceptionally). Provides the final kotlinx.rpc.grpc.GrpcStatus and the sent GrpcMetadata trailers.

Link copied to clipboard
abstract fun proceed(request: Flow<Request>): Flow<Response>

Continue processing by forwarding the request to the next interceptor or the actual service implementation.

Link copied to clipboard
open suspend fun FlowCollector<Response>.proceedUnmodified(request: Flow<Request>)

Convenience for flow builders: proceeds with request and emits the resulting response elements into this FlowCollector. Useful inside flow {} blocks within interceptors.