Close method

  1. @override
void Close()
override
Closes the response stream. A body that was not read is discarded, and a body that is still being read (e.g. a hanging request) ends.

Implementation

@override
void Close() {
  if (_isClosed) {
    return;
  }
  _isClosed = true;
  final controller = _bodyController;
  if (!_isBodyListened) {
    // The body was never read: drain it so the connection is released.
    _isBodyListened = true;
    unawaited(httpClientResponse.drain<void>().catchError((Object _) {}));
  }
  if (controller != null) {
    final subscription = _bodySubscription;
    _bodySubscription = null;
    if (subscription != null) {
      unawaited(subscription.cancel());
    }
    if (!controller.isClosed) {
      unawaited(controller.close());
    }
  }
}