mirror of https://github.com/grpc/grpc-dart.git
* GrpcOrGrpcWeb: remove checking if ports are different (#482) Using the same port is a standard for AspNetCore gRPC server. * improve source docs
This commit is contained in:
parent
e88b84a993
commit
7c8fca7195
|
@ -17,9 +17,13 @@
|
||||||
/// on all platfroms except web, on which it uses [GrpcWebClientChannel].
|
/// on all platfroms except web, on which it uses [GrpcWebClientChannel].
|
||||||
///
|
///
|
||||||
/// Note that gRPC and gRPC-web are 2 different protocols and server must be
|
/// Note that gRPC and gRPC-web are 2 different protocols and server must be
|
||||||
/// able to speak both of them (on separate ports) for this to work. Therefore
|
/// able to speak both of them for this to work.
|
||||||
/// applications using this class must provide both ports and the channel will
|
/// As several existing implementations (such as in-process gRPC-web to gRPC
|
||||||
/// use the one for the actual protocol being used.
|
/// proxies or Envoy gRPC-web to gRPC proxy) expose gRPC and gRPC-web on
|
||||||
|
/// separate ports, the constructor requires 2 ports to be provided and
|
||||||
|
/// the channel will use the one for the actual protocol being used.
|
||||||
|
/// If the server supports both protocols on the same port (such as AspNetCore
|
||||||
|
/// implementation), then the same port value should be provided on both params.
|
||||||
|
|
||||||
export 'src/client/grpc_or_grpcweb_channel_grpc.dart'
|
export 'src/client/grpc_or_grpcweb_channel_grpc.dart'
|
||||||
if (dart.library.html) 'src/client/grpc_or_grpcweb_channel_web.dart';
|
if (dart.library.html) 'src/client/grpc_or_grpcweb_channel_web.dart';
|
||||||
|
|
|
@ -31,11 +31,7 @@ class GrpcOrGrpcWebClientChannel extends ClientChannel {
|
||||||
? ChannelCredentials.secure()
|
? ChannelCredentials.secure()
|
||||||
: ChannelCredentials.insecure(),
|
: ChannelCredentials.insecure(),
|
||||||
),
|
),
|
||||||
) {
|
);
|
||||||
if (grpcWebPort == grpcPort) {
|
|
||||||
throw ArgumentError('grpcPort and grpcWebPort cannot be the same');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
GrpcOrGrpcWebClientChannel.grpc(
|
GrpcOrGrpcWebClientChannel.grpc(
|
||||||
Object host, {
|
Object host, {
|
||||||
|
|
|
@ -23,11 +23,7 @@ class GrpcOrGrpcWebClientChannel extends GrpcWebClientChannel {
|
||||||
required int grpcWebPort,
|
required int grpcWebPort,
|
||||||
required bool secure,
|
required bool secure,
|
||||||
}) : super.xhr(Uri(
|
}) : super.xhr(Uri(
|
||||||
host: host, port: grpcWebPort, scheme: secure ? 'https' : 'http')) {
|
host: host, port: grpcWebPort, scheme: secure ? 'https' : 'http'));
|
||||||
if (grpcWebPort == grpcPort) {
|
|
||||||
throw ArgumentError('grpcPort and grpcWebPort cannot be the same');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
GrpcOrGrpcWebClientChannel.grpc(
|
GrpcOrGrpcWebClientChannel.grpc(
|
||||||
Object host, {
|
Object host, {
|
||||||
|
|
|
@ -36,17 +36,6 @@ void main() {
|
||||||
expect(channel.options.credentials.isSecure, isFalse);
|
expect(channel.options.credentials.isSecure, isFalse);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Constructor throws throwsArgumentError if ports are the same', () {
|
|
||||||
expect(
|
|
||||||
() => GrpcOrGrpcWebClientChannel(
|
|
||||||
host: host,
|
|
||||||
grpcPort: grpcPort,
|
|
||||||
grpcWebPort: grpcPort,
|
|
||||||
secure: false,
|
|
||||||
),
|
|
||||||
throwsArgumentError);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Constructor grpc on non-web passes params correctly', () {
|
test('Constructor grpc on non-web passes params correctly', () {
|
||||||
final options = ChannelOptions(credentials: ChannelCredentials.insecure());
|
final options = ChannelOptions(credentials: ChannelCredentials.insecure());
|
||||||
final channel = GrpcOrGrpcWebClientChannel.grpc(
|
final channel = GrpcOrGrpcWebClientChannel.grpc(
|
||||||
|
|
|
@ -36,17 +36,6 @@ void main() {
|
||||||
equals(Uri(host: host, port: grpcWebPort, scheme: 'https')));
|
equals(Uri(host: host, port: grpcWebPort, scheme: 'https')));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Constructor throws throwsArgumentError if ports are the same', () {
|
|
||||||
expect(
|
|
||||||
() => GrpcOrGrpcWebClientChannel(
|
|
||||||
host: host,
|
|
||||||
grpcPort: grpcPort,
|
|
||||||
grpcWebPort: grpcPort,
|
|
||||||
secure: false,
|
|
||||||
),
|
|
||||||
throwsArgumentError);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Constructor grpc on web throws UnsupportedError', () {
|
test('Constructor grpc on web throws UnsupportedError', () {
|
||||||
expect(() => GrpcOrGrpcWebClientChannel.grpc(host, port: grpcPort),
|
expect(() => GrpcOrGrpcWebClientChannel.grpc(host, port: grpcPort),
|
||||||
throwsUnsupportedError);
|
throwsUnsupportedError);
|
||||||
|
|
Loading…
Reference in New Issue