sendJson method
Sends a JSON response.
Implementation
void sendJson(dynamic data, {String? contentType}) {
if (_sent) return;
_headers
.setContentTypeString(contentType ?? 'application/json; charset=utf-8');
final jsonString =
data is String ? data : JsonEncoder(_defaultToEncodable).convert(data);
if (_compression) {
_response.add(gzip.encode(_safeUtf8Encode(jsonString)));
} else {
_response.add(_safeUtf8Encode(jsonString));
}
_closeResponse();
}