close method
Prevents more data from being written to the response, and locks it entire from further editing.
Implementation
@override
Future close() async {
if (!_isDetached) {
if (!_isClosed) {
if (!isBuffered) {
// Finalizer failures propagate, leaving the response open for the
// error handler.
if (_finalizing != null ||
hasPendingFinalizers ||
_finalizerError != null) {
await _commitOrThrow();
}
try {
_openStream();
_flushQueued();
// Flushes the compression trailer, if any.
_encoderSink?.close();
// Observe the result: an unhandled failure here (e.g. the
// connection dropped) would otherwise terminate the server.
rawResponse.close().catchError((Object e, StackTrace st) {
app?.logger.warning('Failed to send response', e, st);
});
} catch (_) {
// This only seems to occur on `MockHttpRequest`, but
// this try/catch prevents a crash.
}
} else {
_buffer!.lock();
}
_isClosed = true;
}
await super.close();
}
}