From a6f6e986eac6dc34bab4e094a4a35bf5a90ff16e Mon Sep 17 00:00:00 2001 From: Ricardo Durao Date: Mon, 26 May 2025 11:01:14 +0100 Subject: [PATCH] feat: make default options platform aware --- lib/src/client/call_options/call_options.dart | 17 ++++++++++++++ .../call_options/call_options_grpc.dart | 23 +++++++++++++++++++ .../call_options/call_options_grpcweb.dart | 23 +++++++++++++++++++ lib/src/client/client.dart | 3 ++- 4 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 lib/src/client/call_options/call_options.dart create mode 100644 lib/src/client/call_options/call_options_grpc.dart create mode 100644 lib/src/client/call_options/call_options_grpcweb.dart diff --git a/lib/src/client/call_options/call_options.dart b/lib/src/client/call_options/call_options.dart new file mode 100644 index 0000000..4622585 --- /dev/null +++ b/lib/src/client/call_options/call_options.dart @@ -0,0 +1,17 @@ +// Copyright (c) 2018, the gRPC project authors. Please see the AUTHORS file +// for details. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +export 'call_options_grpc.dart' + if (dart.library.js_interop) 'call_options_grpcweb.dart'; diff --git a/lib/src/client/call_options/call_options_grpc.dart b/lib/src/client/call_options/call_options_grpc.dart new file mode 100644 index 0000000..fed2c96 --- /dev/null +++ b/lib/src/client/call_options/call_options_grpc.dart @@ -0,0 +1,23 @@ +// Copyright (c) 2018, the gRPC project authors. Please see the AUTHORS file +// for details. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import '../../../grpc.dart'; + +/// +/// Call options for gRPC. +/// +CallOptions callOptions() { + return CallOptions(); +} diff --git a/lib/src/client/call_options/call_options_grpcweb.dart b/lib/src/client/call_options/call_options_grpcweb.dart new file mode 100644 index 0000000..a0e0789 --- /dev/null +++ b/lib/src/client/call_options/call_options_grpcweb.dart @@ -0,0 +1,23 @@ +// Copyright (c) 2018, the gRPC project authors. Please see the AUTHORS file +// for details. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import '../../../grpc_web.dart'; + +/// +/// Call options for gRPC-web. +/// +CallOptions callOptions() { + return WebCallOptions(withCredentials: true); +} diff --git a/lib/src/client/client.dart b/lib/src/client/client.dart index 1ba6d00..ece4e60 100644 --- a/lib/src/client/client.dart +++ b/lib/src/client/client.dart @@ -14,6 +14,7 @@ // limitations under the License. import 'call.dart'; +import 'call_options/call_options.dart'; import 'channel.dart'; import 'common.dart'; import 'interceptor.dart'; @@ -28,7 +29,7 @@ class Client { /// Interceptors will be applied in direct order before making a request. Client(this._channel, {CallOptions? options, Iterable? interceptors}) - : _options = options ?? CallOptions(), + : _options = options ?? callOptions(), _interceptors = List.unmodifiable(interceptors ?? Iterable.empty()); @Deprecated(r'''This method does not invoke interceptors and is superseded