close method
Close the target consumer.
NOTE: Writes to the IOSink may be buffered, and may not be flushed by
a call to close(). To flush all buffered writes, call flush() before
calling close().
Implementation
@override
Future close() async {
final web.ResponseInit responseInit = web.ResponseInit(
status: statusCode,
statusText: reasonPhrase,
);
final web.Response response = web.Response(
() {
if (_content is String) {
try {
return _content.toJS;
} catch (e) {
return json.encode(json.decode(_content)).toJS;
}
} else if (_content is num) {
return _content.toJS;
} else if (_content is Map || _content is List) {
return json.encode(_content).toJS;
} else {
return (_content ?? "").toString().toJS;
}
}(),
responseInit,
);
{
_httpHeaders.forEach((key, values) {
response.headers.set(key, values.join("; "));
});
final contentType = _httpHeaders.contentType;
if (contentType != null) {
response.headers.set("content-type", contentType.value);
}
}
return response;
}