toMap method

Map<String, dynamic> toMap({
  1. int? maxBodyChars,
})

Implementation

Map<String, dynamic> toMap({int? maxBodyChars}) {
  final hasLimit = maxBodyChars != null && maxBodyChars >= 0;
  final limitedBody = hasLimit && body.length > maxBodyChars
      ? body.substring(0, maxBodyChars)
      : body;

  return {
    'uri': uri.toString(),
    'method': method,
    'statusCode': statusCode,
    'headers': headers,
    'body': limitedBody,
    'bodyLength': body.length,
    'bodyTruncated': limitedBody.length != body.length,
    'isJson': isJson,
    if (isJson) 'json': _tryParseJson(body),
  };
}