Ensure CallOptions merge preserves Web specific options

This commit is contained in:
Zbigniew Mandziejewicz 2020-11-11 18:49:39 +04:00 committed by GitHub
parent 52bea07000
commit 8b71a9dab2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 5 deletions

View File

@ -129,17 +129,24 @@ class WebCallOptions extends CallOptions {
@override
CallOptions mergedWith(CallOptions other) {
if (other == null) return this;
if (other is! WebCallOptions) return super.mergedWith(other);
final mergedMetadata = Map.from(metadata)..addAll(other.metadata);
final mergedTimeout = other.timeout ?? timeout;
final mergedProviders = List.from(metadataProviders)
..addAll(other.metadataProviders);
if (other is! WebCallOptions) {
return WebCallOptions._(Map.unmodifiable(mergedMetadata), mergedTimeout,
List.unmodifiable(mergedProviders),
bypassCorsPreflight: bypassCorsPreflight,
withCredentials: withCredentials);
}
final otherOptions = other as WebCallOptions;
final mergedBypassCorsPreflight =
otherOptions.bypassCorsPreflight ?? bypassCorsPreflight;
final mergedWithCredentials =
otherOptions.withCredentials ?? withCredentials;
final mergedMetadata = Map.from(metadata)..addAll(otherOptions.metadata);
final mergedTimeout = otherOptions.timeout ?? timeout;
final mergedProviders = List.from(metadataProviders)
..addAll(otherOptions.metadataProviders);
return WebCallOptions._(Map.unmodifiable(mergedMetadata), mergedTimeout,
List.unmodifiable(mergedProviders),
bypassCorsPreflight: mergedBypassCorsPreflight,

View File

@ -0,0 +1,16 @@
import 'package:grpc/src/client/call.dart';
import 'package:test/test.dart';
void main() {
test('WebCallOptions mergeWith CallOptions returns WebCallOptions', () {
final options =
WebCallOptions(bypassCorsPreflight: true, withCredentials: true);
final metadata = {"test": "42"};
final mergedOptions =
options.mergedWith(CallOptions(metadata: metadata)) as WebCallOptions;
expect(mergedOptions.metadata, metadata);
expect(mergedOptions.bypassCorsPreflight, true);
expect(mergedOptions.withCredentials, true);
});
}