handleResponseBody static method

String handleResponseBody(
  1. List<int> bytes,
  2. Map<String, String> headers
)

Handle response body based on content type

Implementation

static String handleResponseBody(
    List<int> bytes, Map<String, String> headers) {
  final contentType = headers['content-type']?.toLowerCase() ?? '';

  // JSON responses - decode as text
  if (contentType.contains('application/json')) {
    return utf8.decode(bytes, allowMalformed: true);
  }

  // Text responses - decode as text
  if (contentType.contains('text/')) {
    return utf8.decode(bytes, allowMalformed: true);
  }

  // Binary data - show metadata only
  return '[BINARY_DATA] ${bytes.length} bytes, Content-Type: $contentType';
}