mirror of https://github.com/grpc/grpc-dart.git
Ensure CallOptions merge preserves Web specific options
This commit is contained in:
parent
52bea07000
commit
8b71a9dab2
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue