dispatchCall method

Future<StatusException?> dispatchCall(
  1. CallContext ctx,
  2. Headers headers,
  3. StreamInput input,
  4. ServerSink send,
)

Dispatch one call against the registered handler table with a caller-supplied response sink (raw payloads). This is the seam generated non-gRPC servers (Connect mux) dispatch through, reusing the exact handler table this Server serves as gRPC-DC.

Implementation

Future<StatusException?> dispatchCall(CallContext ctx, Headers headers,
    StreamInput input, ServerSink send) async {
  final method = _methods[headers.path];
  if (method == null) {
    return StatusException(
        Wire.codeUnimplemented, 'unknown method ${headers.path}');
  }
  // Struct codec negotiation: an explicit dc-codec marker
  // must be struct-v1 and enabled here, else Unimplemented.
  var useStruct = false;
  final marker = headers.metadata[Codec.structCodecHeader];
  if (marker != null) {
    if (marker != Codec.structCodecV1 || !_structCodec) {
      return StatusException(
          Wire.codeUnimplemented, 'struct codec not enabled');
    }
    useStruct = true;
  }
  ctx.structCodec = useStruct;
  final traceCtx = traceStart('server', headers.path ?? '',
      parseTraceparent(headers.metadata['traceparent']));
  ctx.traceContext = traceCtx;
  StatusException? result;
  try {
    await method.handler(ctx, RequestStream(input, useStruct), send);
  } catch (e) {
    result = StatusException.toStatus(e);
  }
  traceEnd('server', headers.path ?? '', traceCtx,
      result == null ? 'OK' : Wire.statusName(result.code));
  return result;
}