render method

String? render()

Text for the record: pretty-printed JSON when the whole body is valid JSON and the result fits, otherwise the (cut) text, or a placeholder for bodies that are not UTF-8 text.

Implementation

String? render() {
  if (_totalBytes == 0) return null;
  if (_contentSkipped) return '<binary data: $_totalBytes bytes>';
  final text = _decode(_preview.toBytes(), cutAtEnd: isTruncated);
  if (text == null) return '<binary data: $_totalBytes bytes>';

  if (!isTruncated) {
    final pretty = _prettyJson(text);
    if (pretty != null && escapedLength(pretty) <= limit) return pretty;
  }
  return fitToLimit(text, limit, truncated: isTruncated);
}