GetResponseStream method
Gets the stream that is used to read the body of the response from the server.
Implementation
@override
Stream<List<int>> GetResponseStream() {
final existing = _bodyController;
if (existing != null) {
return existing.stream;
}
late final StreamController<List<int>> controller;
controller = StreamController<List<int>>(
onListen: () {
if (_isClosed) {
unawaited(controller.close());
return;
}
_isBodyListened = true;
_bodySubscription = httpClientResponse.listen(
controller.add,
onError: controller.addError,
onDone: () {
_bodySubscription = null;
unawaited(controller.close());
},
);
},
onPause: () => _bodySubscription?.pause(),
onResume: () => _bodySubscription?.resume(),
onCancel: () {
final subscription = _bodySubscription;
_bodySubscription = null;
return subscription?.cancel();
},
);
_bodyController = controller;
return controller.stream;
}