Response.fromString constructor

Response.fromString(
  1. String body, {
  2. int status = 200,
  3. Headers? headers,
})

Creates a new Response from string value.

Implementation

factory Response.fromString(
  String body, {
  int status = 200,
  Headers? headers,
}) {
  final bytes = utf8.encode(body);
  return Response(Stream.value(bytes), status: status, headers: headers)
    ..headers.set('Content-Type', 'text/plain')
    ..headers.set('Content-Length', bytes.lengthInBytes.toString());
}