close method

  1. @override
Future close()
override

Prevents more data from being written to the response, and locks it entire from further editing.

Implementation

@override
Future close() {
  // Not async, which would cost a Future and a microtask per response; an
  // error still fails the Future returned, as it did.
  try {
    if (_isDetached) return Future.value();
    if (!_isClosed && isBuffered) {
      _buffer!.lock();
      _isClosed = true;
    }
    if (_isClosed) return super.close();
    // Finalizer failures propagate, leaving the response open for the
    // error handler.
    if (_finalizing != null ||
        hasPendingFinalizers ||
        _finalizerError != null) {
      return _commitOrThrow().then((_) => _closeStream());
    }
    return _closeStream();
  } catch (e, st) {
    return Future.error(e, st);
  }
}