grpc-dart icon indicating copy to clipboard operation
grpc-dart copied to clipboard

How to specify service version for grpc-Web? unencodedPath from Uri.https is ignored

Open r-durao-pvotal opened this issue 2 years ago • 0 comments

We've been trying to add versioning to grpc services client side, and we tried to do the following when creating web client channels:

  final clientChannel = GrpcWebClientChannel.xhr(
    Uri.https(
      authority,
      '/v4/',
    ),
  );

Do note that it's not possible to add the version to the authority as the Uri class will throw a format exception. This in theory should work per the Uri.https documentation, however, onConnectionReady of the ClientCall class doesn't care about the unencodedPath of a Uri because it works with a generic ClientConnection and not a XhrClientConnection

  void onConnectionReady(ClientConnection connection) {
    if (isCancelled) return;

    if (options.metadataProviders.isEmpty) {
      _sendRequest(connection, _sanitizeMetadata(options.metadata));
    } else {
      final metadata = Map<String, String>.from(options.metadata);

      Future.forEach(
              options.metadataProviders,
              (MetadataProvider provider) => provider(metadata,
                  '${connection.scheme}://${connection.authority}${audiencePath(_method)}'))
          .then((_) => _sendRequest(connection, _sanitizeMetadata(metadata)))
          .catchError(_onMetadataProviderError);
    }
  }

Should there be a web version of ClientCall with its own implementation of onConnectionReady ?

<3.0.0>

r-durao-pvotal avatar May 10 '22 08:05 r-durao-pvotal