Unverified Commit e8270ff6 authored by Todd Volkert's avatar Todd Volkert Committed by GitHub

Prepare for HttpClientResponse Uint8List SDK change (#34863)

* Prepare for HttpClientResponse Uint8List SDK change

An upcoming change in the Dart SDK will change `HttpClientResponse`
from implementing `Stream<List<int>>` to instead implement
`Stream<Uint8List>`.

This forwards-compatible change to `_MockHttpClientResponse` is being
made to allow for a smooth rollout of that SDK breaking change. The
current structure of the class is as follows:

```dart
_MockHttpClientResponse extends Stream<List<int>> implements HttpClientResponse {
  ...
}
```

This structure would require that the Dart SDK change land atomically
a change to the class (`extends Stream<Uint8List>`). This atomic landing
requirement doesn't play well at all with Flutter's roll model vis-a-vis
the Dart SDK's roll model to Google's internal repo.  As such, this commit
changes the structure of `_MockHttpClientResponse` to be:

```dart
_MockHttpClientResponse implements HttpClientResponse {
  final Stream<Uint8List> _delegate;

  ...
}
```

Once the Dart SDK change has fully rolled out, we can simplify this class
back to its former structure.

https://github.com/dart-lang/sdk/issues/36900

* Review comment
parent d6440156
......@@ -1779,7 +1779,11 @@ class _MockHttpRequest extends HttpClientRequest {
}
/// A mocked [HttpClientResponse] which is empty and has a [statusCode] of 400.
class _MockHttpResponse extends Stream<List<int>> implements HttpClientResponse {
// TODO(tvolkert): Change to `extends Stream<Uint8List>` once
// https://dart-review.googlesource.com/c/sdk/+/104525 is rolled into the framework.
class _MockHttpResponse implements HttpClientResponse {
final Stream<Uint8List> _delegate = Stream<Uint8List>.fromIterable(const Iterable<Uint8List>.empty());
@override
final HttpHeaders headers = _MockHttpHeaders();
......@@ -1809,8 +1813,8 @@ class _MockHttpResponse extends Stream<List<int>> implements HttpClientResponse
bool get isRedirect => false;
@override
StreamSubscription<List<int>> listen(void Function(List<int> event) onData, { Function onError, void Function() onDone, bool cancelOnError }) {
return const Stream<List<int>>.empty().listen(onData, onError: onError, onDone: onDone, cancelOnError: cancelOnError);
StreamSubscription<Uint8List> listen(void Function(Uint8List event) onData, { Function onError, void Function() onDone, bool cancelOnError }) {
return const Stream<Uint8List>.empty().listen(onData, onError: onError, onDone: onDone, cancelOnError: cancelOnError);
}
@override
......@@ -1829,6 +1833,189 @@ class _MockHttpResponse extends Stream<List<int>> implements HttpClientResponse
@override
int get statusCode => 400;
@override
Future<bool> any(bool Function(Uint8List element) test) {
return _delegate.any(test);
}
@override
Stream<Uint8List> asBroadcastStream({
void Function(StreamSubscription<Uint8List> subscription) onListen,
void Function(StreamSubscription<Uint8List> subscription) onCancel,
}) {
return _delegate.asBroadcastStream(onListen: onListen, onCancel: onCancel);
}
@override
Stream<E> asyncExpand<E>(Stream<E> Function(Uint8List event) convert) {
return _delegate.asyncExpand<E>(convert);
}
@override
Stream<E> asyncMap<E>(FutureOr<E> Function(Uint8List event) convert) {
return _delegate.asyncMap<E>(convert);
}
@override
Stream<R> cast<R>() {
return _delegate.cast<R>();
}
@override
Future<bool> contains(Object needle) {
return _delegate.contains(needle);
}
@override
Stream<Uint8List> distinct([bool Function(Uint8List previous, Uint8List next) equals]) {
return _delegate.distinct(equals);
}
@override
Future<E> drain<E>([E futureValue]) {
return _delegate.drain<E>(futureValue);
}
@override
Future<Uint8List> elementAt(int index) {
return _delegate.elementAt(index);
}
@override
Future<bool> every(bool Function(Uint8List element) test) {
return _delegate.every(test);
}
@override
Stream<S> expand<S>(Iterable<S> Function(Uint8List element) convert) {
return _delegate.expand(convert);
}
@override
Future<Uint8List> get first => _delegate.first;
@override
Future<Uint8List> firstWhere(
bool Function(Uint8List element) test, {
List<int> Function() orElse,
}) {
return _delegate.firstWhere(test, orElse: orElse);
}
@override
Future<S> fold<S>(S initialValue, S Function(S previous, Uint8List element) combine) {
return _delegate.fold<S>(initialValue, combine);
}
@override
Future<dynamic> forEach(void Function(Uint8List element) action) {
return _delegate.forEach(action);
}
@override
Stream<Uint8List> handleError(
Function onError, {
bool Function(dynamic error) test,
}) {
return _delegate.handleError(onError, test: test);
}
@override
bool get isBroadcast => _delegate.isBroadcast;
@override
Future<bool> get isEmpty => _delegate.isEmpty;
@override
Future<String> join([String separator = '']) {
return _delegate.join(separator);
}
@override
Future<Uint8List> get last => _delegate.last;
@override
Future<Uint8List> lastWhere(
bool Function(Uint8List element) test, {
List<int> Function() orElse,
}) {
return _delegate.lastWhere(test, orElse: orElse);
}
@override
Future<int> get length => _delegate.length;
@override
Stream<S> map<S>(S Function(Uint8List event) convert) {
return _delegate.map<S>(convert);
}
@override
Future<dynamic> pipe(StreamConsumer<List<int>> streamConsumer) {
return _delegate.pipe(streamConsumer);
}
@override
Future<Uint8List> reduce(List<int> Function(Uint8List previous, Uint8List element) combine) {
return _delegate.reduce(combine);
}
@override
Future<Uint8List> get single => _delegate.single;
@override
Future<Uint8List> singleWhere(bool Function(Uint8List element) test, {List<int> Function() orElse}) {
return _delegate.singleWhere(test, orElse: orElse);
}
@override
Stream<Uint8List> skip(int count) {
return _delegate.skip(count);
}
@override
Stream<Uint8List> skipWhile(bool Function(Uint8List element) test) {
return _delegate.skipWhile(test);
}
@override
Stream<Uint8List> take(int count) {
return _delegate.take(count);
}
@override
Stream<Uint8List> takeWhile(bool Function(Uint8List element) test) {
return _delegate.takeWhile(test);
}
@override
Stream<Uint8List> timeout(
Duration timeLimit, {
void Function(EventSink<Uint8List> sink) onTimeout,
}) {
return _delegate.timeout(timeLimit, onTimeout: onTimeout);
}
@override
Future<List<Uint8List>> toList() {
return _delegate.toList();
}
@override
Future<Set<Uint8List>> toSet() {
return _delegate.toSet();
}
@override
Stream<S> transform<S>(StreamTransformer<List<int>, S> streamTransformer) {
return _delegate.transform<S>(streamTransformer);
}
@override
Stream<Uint8List> where(bool Function(Uint8List event) test) {
return _delegate.where(test);
}
}
/// A mocked [HttpHeaders] that ignores all writes.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment